Q:

c# Generics help - how to pass params to new T()

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

A:

The new() keyword by definition restricts your generic parameter to be a reference type with a public, parameterless constructor.  When you instantiate a "new T()", it has to use reflection to create an instance of it.  
You may want to use a factory pattern to create your objects instead of trying to do it through a generic constructor.  You could pass the type into the factory and have the factory logic pass you back the correct object type, initialized with the user.

