I have the following base class:
public class Base { public string LogicalName { get; set; } public int NumberOfChars { get; set; } public Base() { } public Base(string logicalName, int numberOfChars) { LogicalName = logicalName; NumberOfChars = numberOfChars; } }
and the following derived classes:
public class Derived1 : Base { public const string EntityLogicalName = "Name1"; public const int EntityNumberOfChars = 30; public Derived1() : base(EntityLogicalName, EntityNumberOfChars) { } } public class Derived2 : Base { public const string EntityLogicalName = "Name2"; public const int EntityNumberOfChars = 50; public Derived2() : base(EntityLogicalName, EntityNumberOfChars) { } }
and I also have this function provided by the service:
public IEnumerable<T> GetEntities<T>(string entityName, int numberOfChars) where T : Base {
My problem is how can I call this function in general? I want to call it something that looks like this:
public void TestEntities<T>() where T : Base { var entities = GetEntities<T>(T.EntityLogicalName, T.EntityNumberOfChars);
This, of course, does not work, because at the moment T is unknown. How can I do something like this? EntityLogicalName and EntityNumberOfChars are characteristics that all Base classes have, and they never change for each derived class. Can I get them from the base class without instantiating objects or in any other way that I don't see?
source share