I want to access a property of a new created object within a generic method, which is constraint by an Interface:
public interface MyInterface
{
int ID { get; set; }
string Name { get; set; }
}
Since the Compiler knows that "T" is of the Type MyInterface it should be possible to access the properties of that inteface:
public T doSomething<T>(String value) where T : MyInterface, new()
{
T entity = new T();
entity.Name = value;
return entity;
}
But it sais: T does not have a definition for 'Name'
If I can use an interface as a constraint here: Why isn't it possible to access its properties?