I have backed myself into a a bit of a corner. Here is a simplified version of what I have (in C#):
class OuterClass
{
private class BadClass
{
private int Data;
public BadClass()
{
Data = 0;
...
}
}
T Build<T>(Object Input)
{
T x = new T();
...
return x;
}
void SomeMethod()
{
BadClass a = Build<BadClass>(anObject);
...
}
...
}
The problem I have is that I now must change the initial value of Data depending on the instance of OuterClass that is creating the BadClass instance. Normally I would simply use a BadClass constructor that takes a parameter:
public BadClass(int Data)
{
this.Data = Data;
...
}
But I use BadClass in several generic types so I must have a parameterless BadClass constructor. Too bad I can't do something like this:
Build<BadClass(5)>(anObject);
So, how do I give a constructor run-time information when I can't pass parameters into the constructor?
Is it possible to create a runtime instance of a BadClass type, give it the information it needs, and then use that in my generic types?
EDIT: I used List as an example generic type but that didn't fully express the depth of my dilemma...
I can create a test in Build to call an init function if I am working with a BadClass, but that is very hacky. I am hoping to find a slightly less ugly way to go about it.