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 Removed)
"Andrus" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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 [.NET/C# MVP]" <(E-Mail Removed)> wrote
> in message news:%(E-Mail Removed)...
>> 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 Removed)
>>
>> "Andrus" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Why this limitation exists ?
>>>
>>> I want to assing values to some properties in constructor.
>>> Any idea how this can be done ?
>>>
>>> Andrus.
>>>
>>> "Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote
>>> in message news:(E-Mail Removed)...
>>>> 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.
>>>
>>
>>
>