>Paul,
>
>Why we can not use Generics here? The method will return an object of specified type and also will receive a parameter of the specified type.
>
He wants to be able to pass in a string, generics wouldn't help here. You can't have a method who's signature only differs by return type. Generics also doesn't automagically convert types for you, so assuming this is coming from a configuration file, he has to cast the string back into the original type.
However, he could also create a number of overloaded methods and pass a parameter by reference which gets filled in:
int testInt = 0;
SettingsManager("SomeProperty", out testInt);
string testString = "";
SettingsManager("SomeOtherProperty", out testString);
public class SettingsManager
{
public static void GetValue(string propertyName, out int returnValue)
{
returnValue = 1;
}
public static void GetValue(string propertyName, out string returnValue)
{
returnValue = "Hello";
}
}
It's a little ugly, but it would work. I'd still prefer the strongly-typed class interface instead.