G
Guest
Hi
I need to parse strings to enumerated types for several different
enumerated types. Im doing this for each of them, bu I wonder if there is a
way to write a generic method that also takes the specific enumerated type as
an argument. Is it possible to pass the typeof(enum) as an argument, and how
is it done? See current method below.
regards Jesper.
private static Week WeekFromStr(string str)
{
try
{
return (Week)Enum.Parse(typeof(Week), str);
}
catch ( Exception e )
{
throw new Exception("WeekFromStr error " + e.Message);
}
return Week.na;
}
I need to parse strings to enumerated types for several different
enumerated types. Im doing this for each of them, bu I wonder if there is a
way to write a generic method that also takes the specific enumerated type as
an argument. Is it possible to pass the typeof(enum) as an argument, and how
is it done? See current method below.
regards Jesper.
private static Week WeekFromStr(string str)
{
try
{
return (Week)Enum.Parse(typeof(Week), str);
}
catch ( Exception e )
{
throw new Exception("WeekFromStr error " + e.Message);
}
return Week.na;
}