[EDIT]
I organize my question again,
Models for parameter
public class PaymentModel
{
...
}
public class CCPaymentModel : PaymentModel
{
...
}
public class PaypalPaymentModel : PaymentModel
{
...
}
public class GooglePaymentModel : PaymentModel
{
...
}
Interface class
public interface IPayment<T> where T : PaymentModel
{
...
}
Models (get inheritance from IPayment),
public class SagePayment
: IPayment<CreditCardPaymentInfo>
{
public void MakePayment( CreditCardPaymentInfo creditCardPaymentInfo ) {
// ...
}
public void MakeRefund( CreditCardPaymentInfo creditCardPaymentInfo ) {
// ...
}
}
public class GooglePayment
: IPayment<GooglePaymentModel>
{
public void MakePayment( GooglePaymentModel paymentInfo ) {
// ...
}
public void MakeRefund( GooglePaymentModel paymentInfo ) {
// ...
}
}
public class PaypalPayment
: IPayment<PayPalPaymentModel>
{...}
Controller (Create instance)
IPayment<???> paymentProcess; // //Error 1 Using the generic type 'com.WebUI.Models.IPayment<T>' requires 1 type arguments
if (Regex.IsMatch(paytype, "^Credit Card"))
{
paymentProcess = new SagePayment(); // it need CCPaymentModel type parameter
}
else if (Regex.IsMatch(paytype, "^PayPal"))
{
paymentProcess = new PayPalPayment(); // it need PaypalPaymentModel type parameter
}
else if (Regex.IsMatch(paytype, "^Google"))
{
paymentProcess = new GooglePayment(); // it need GooglePaymentModel type parameter
}
[EDIT]
public void Charge(string paytype,orderNo){
IPayment<???> paymentProcess; // //Error 1 Using the generic type 'com.WebUI.Models.IPayment<T>' requires 1 type arguments
Object payinfo;
if (Regex.IsMatch(paytype, "^Credit Card"))
{
paymentProcess = new SagePayment(); // <== Error, Can not casting
payinfo = getPaymentInfo(paytype, orderNo); // it return CCPaymentModel type object
}
else if (Regex.IsMatch(paytype, "^PayPal"))
{
paymentProcess = new PayPalPayment();
payinfo = getPaymentInfo(paytype, orderNo); // it return PaypalPaymentModel type object
}
else if (Regex.IsMatch(paytype, "^Google"))
{
paymentProcess = new GooglePayment(); // it return GooglePaymentModel type object
payinfo = getPaymentInfo(paytype, orderNo);
}
paymentProcess.MakePayment(payinfo);
}

[EDIT #2]
With this,
public interface IPayment {
}
public interface IPayment<T> : IPayment where T : PaymentModel
{
void MakePayment(string pickno);
void makeRefund(T refundInfo);
}
I got an error, Error 1 'com.WebUI.Models.IPayment' does not contain a definition for 'MakePayment' and no extension method 'MakePayment' accepting a first argument of type 'Ecom.WebUI.Models.IPayment' could be found (are you missing a using directive or an assembly reference?)
So, to avoid that error, I move MakePayment method to upper interface class,
public interface IPayment {
void MakePayment(string pickno);
}
public interface IPayment<T> : IPayment where T : PaymentModel
{
void makeRefund(T refundInfo);
}
Now, the error is gone, BUT how should I do in makeRefund case? I can not move to upper interface class because I need generic type parameter.
Could you help me a little more please?
IPaymentinterface without the generics from whichIPayment<T>inherits from. That is:public interface IPayment<T> : IPayment where T : PaymentModel.GooglePayment,PayPalPayment, etc classes (but not shown here) which implement fromIPayment<GooglePaymentModel>orIPayment<PayPalPayment>respectively.