Given a constructor
public MyObject(int id){
ID = id;
}
And two enums:
public enum MyEnum1{
Something = 1,
Anotherthing = 2
}
public enum MyEnum2{
Dodo = 1,
Moustache= 2
}
Is it possible to pass in a generic enum as a parameter of the constructor? I'm looking for a solution along the lines of:
public MyObject(enum someEnum){
ID = (int)someEnum;
}
So you can do:
var newObject = new MyObject(MyEnum1.Something);
var anotherObject = new MyObject(MyEnum2.Dodo);
MyBase b = new MySub<EnumA>(EnumA.SomeValue); int n = b.ID;
– Guibertnew MyObject((int)MyEnum1.Something);
? – Clantonenum
and pass that to a factory that in turn creates the right thing with the rightenum
parameter.var newObject = myFactory.Create(ObjectType.One)
. – Nipissing