Andrus,
In this case, you would have to have EntityType be in the class itself,
and then do this:
public BusinessObjectGeneric<TEntityType> where TEntityType : new()
{
public BusinessObjectGeneric(string param)
{
TEntityType entity = new TEntityType();
}
}
Now, the thing here is that the property you want to set has to come
from a base class/interface which you specify in the constraints, or you
have to access it through reflection.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Andrus said:
I'd like to create new entity object in business object constructor:
public BusinessObjectGeneric<EntityType> (string param) {
Entity = new <EntityType> ();
if (Entity!=null)
Entity.propery = param;
}
Andrus.
Nicholas Paldino said:
Andrus,
What kind of properties are you trying to assign to in the
constructor?
What would you like to be able to do if the compiler let you?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Andrus said:
Why this limitation exists ?
I want to assing values to some properties in constructor.
Any idea how this can be done ?
Andrus.
in message Andrus,
You can't create a generic class constructor. If you want to take
advantage of parameterized types in the constructor, then you will have
to take the type in the class declaration level.