Possible Duplicate:
Create instance of generic type?
How can I pass a param to a generic contstructor?
public class Payment<T> where T: HostFunctionContext, IClaimPayment, new()
{
public IResultEntity Display(MyUser user, string claim, int? cert)
{
**HostFunctionContext func = new T(user) as HostFunctionContext;** <~doesn't compile
IClaimPayment payment = new T();
payment.ClaimNumber = claimNumber;
payment.CertificateSequence = certSequence;
return payment.DisplayEntity();
}
}
public sealed partial class CardPayment : HostFunctionContext
{
public CardPayment(MyUser user) : base(user) { }
}
constructor for abstract HostFunctionContext
public HostFunctionContext(MyUser user) {
_hostConnection = HostConnectionAssembler.GetHostConnection();
_functionParams = FunctionParamsAssembler.GetFunctionParams();
if (user != null) {
_hostConnection.Login = user.Login;
}
}
I need to pass the user to the baseclass of T. How can I do this? Do I create a parameterless constructor, then a property of type MyUser, then on the set of that property push that to the baseclass? The abstract baseclass has no myUser property and no parameterless constructor. I am really stuck here.
Thanks for any help, ~ck