Dattu
asked on
calling extension methods and calling them in data contracts
Hi,
I have using a 3 party payment cart provided by chase.
below is a extension method. Irequest is the object provided by chase for sending them a request.
String ordernumber is anything string.
Suppose , i want to call this SetMerchantOrderNumber(thi s IRequest request, string orderNumber) in another class, how do i call it. i know i have to using this class using using in class file.
also, how do i mport this into datacontracts for sending the request to chase using wcf.
using System;
using System.Collections.Generic ;
using System.Linq;
using ChasePaymentech.Spectrum;
using Vertrue.Core.String;
using Vertrue.Core.PaymenTech.Ex ceptions;
using Vertrue.Core.PaymenTech.Ex tensions.C reditCardV endors;
using Vertrue.Core.PaymenTech.In terfaces;
namespace Vertrue.Core.PaymenTech.Ex tensions.R equest
{
public static class IRequestExtensions
{
/// <summary>
/// Validates the value passed in does not contain invalid characters and sets the MerchantOrderNumber property on the request.
/// </summary>
/// <param name="request">Any Paymentech request.</param>
/// <param name="orderNumber">A string value must not contaion |,^,%,\,/,[,],`,~ characters and must be less than 23 characters.</param>
public static void SetMerchantOrderNumber(thi s IRequest request, string orderNumber)
{
if (!string.IsNullOrWhiteSpac e(orderNum ber))
{
var invalidCharacters = new HashSet<char> { '|', '^', '%', '\\', '/', '[', ']', '~', '`' };
const int merchantOrderNumbermaxLeng th = 22;
//check for invalid characters
if (orderNumber.ToCharArray() .Any(inval idCharacte rs.Contain s))
throw new ArgumentContainsInvalidCha racterExce ption("val ue", invalidCharacters);
//check for invalid length
if (!orderNumber.IsValidLengt h(merchant OrderNumbe rmaxLength ))
throw new ArgumentToLongException("v alue", merchantOrderNumbermaxLeng th);
//should be left aligned and padded with spaces.
orderNumber = orderNumber.Trim().Length == 0 ? null : orderNumber.PadRight(22, ' ');
}
else
orderNumber = null;
const string merchantOrderNumberKey = "MerchantOrderNumber";
request[merchantOrderNumbe rKey] = orderNumber;
}
I have using a 3 party payment cart provided by chase.
below is a extension method. Irequest is the object provided by chase for sending them a request.
String ordernumber is anything string.
Suppose , i want to call this SetMerchantOrderNumber(thi
also, how do i mport this into datacontracts for sending the request to chase using wcf.
using System;
using System.Collections.Generic
using System.Linq;
using ChasePaymentech.Spectrum;
using Vertrue.Core.String;
using Vertrue.Core.PaymenTech.Ex
using Vertrue.Core.PaymenTech.Ex
using Vertrue.Core.PaymenTech.In
namespace Vertrue.Core.PaymenTech.Ex
{
public static class IRequestExtensions
{
/// <summary>
/// Validates the value passed in does not contain invalid characters and sets the MerchantOrderNumber property on the request.
/// </summary>
/// <param name="request">Any Paymentech request.</param>
/// <param name="orderNumber">A string value must not contaion |,^,%,\,/,[,],`,~ characters and must be less than 23 characters.</param>
public static void SetMerchantOrderNumber(thi
{
if (!string.IsNullOrWhiteSpac
{
var invalidCharacters = new HashSet<char> { '|', '^', '%', '\\', '/', '[', ']', '~', '`' };
const int merchantOrderNumbermaxLeng
//check for invalid characters
if (orderNumber.ToCharArray()
throw new ArgumentContainsInvalidCha
//check for invalid length
if (!orderNumber.IsValidLengt
throw new ArgumentToLongException("v
//should be left aligned and padded with spaces.
orderNumber = orderNumber.Trim().Length == 0 ? null : orderNumber.PadRight(22, ' ');
}
else
orderNumber = null;
const string merchantOrderNumberKey = "MerchantOrderNumber";
request[merchantOrderNumbe
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> i am looking for the exact syntax, pleasee....
I gave you the syntax in line 3 of my post. You asked for the syntax to call an extension method, not how to declare an interface. And I stated in my post that the variable declaration was not proper.
To make the declaration proper, set it equal to a new instance of any class which implements IRequest.
I gave you the syntax in line 3 of my post. You asked for the syntax to call an extension method, not how to declare an interface. And I stated in my post that the variable declaration was not proper.
To make the declaration proper, set it equal to a new instance of any class which implements IRequest.
ASKER
Sorry, it tok me so long to close this questiona and had to give points to both of you. I wish I give each of you 250 points. Sorry again for the delay.
ASKER
i am looking for the exact syntax, pleasee....
Irequest is an interface.