Reputation: 315
I have an abstract class, and I want to let the derived class define not only the value type, but let them define how many value types they have. Then I want to require them to have getters/setters for each type:
public abstract class A<T1, T2, ..., TN>
{
// Getters
public abstract T1 GetValue();
public abstract T2 GetValue();
...
public abstract TN GetValue();
// Setters
public abstract void SetValue(T1 newVal);
public abstract void SetValue(T2 newVal);
...
public abstract void SetValue(TN newVal);
}
Then the classes that derive from A can have as many values as they want, as long as they provide access to them. Is this possible in c#? Or something similar to it?
Upvotes: 0
Views: 48
Reputation: 190925
No. They must be explicitly defined because the compiler has to figure out what to do with the types to build into the assembly.
You could obtain a similar effect via a code generator.
Upvotes: 5