Given an enum type:
public enum Work
{
Normal,
Extended
}
What I would like to do is the following.
public abstract class Builder<T>
{
public static Builder<T> GetBuilder<T> (T work)
{
return new Builder<T> ();
}
}
public class BuilderNormal : Builder<Work.Normal>
{
}
public class BuilderExtended : Builder<Work.Extended>
{
}
I specifically want to avoid using a switch/case in Builder or using a mapping that I would need to maintain when I would add a new enum value to Work, i.e. I could do this
public abstract class Builder
{
public static Builder GetBuilder (Work work)
{
switch (work)
{
case Work.Normal:
return new BuilderNormal ();
case Work.Extended:
return new BuilderExtended ();
default:
throw new ...
}
}
}
So, basically, I want to create an instance of a class depending on an enum value and the class must be a child class of an abstract class.