I have a class named config with one string field named key.
When I apply the GET property of the class, the property has to return one variable key in different types (Int or bool or String).
I implemented it as follow:
public enum RetType {RetInt, RetBool, RetString};
...
public object PolimorphProperty(string key, RetType how)
{
get
{
switch (how)
{
case RetType.RetInt:
...;
case RetType.RetBool:
...;
case RetType.RetString:
...;
}
}
}
But the problem that PolimorphProperty returns Object type.
What should I change in the code to get the appropriate type (int,bool,string), not the object?
Do this:
Usage example:
And this supports the http://www.antiifcampaign.com/
As much as possible avoid
switch,iffor that matter, in a polymorphic code.