1
我是使用泛型类的新手。这里是我的问题:通用方法根据输入参数返回值
我有几个枚举,如:x.PlatformType,y.PlatformType,z.PlatformType等等
public class Helper<T>
{
public T GetPlatformType(Type type)
{
switch (System.Configuration.ConfigurationManager.AppSettings["Platform"])
{
case "DVL":
return // if type is x.PlatformType I want to return x.PlatformType.DVL
// if type is y.PlatformType I want to return y.PlatformType.DVL
// etc
default:
return null;
}
}
}
是否可以开发这样的方法?
预先感谢,
为什么你有几个类似的枚举?配置中的字符串是否总是像您的示例中那样完全是枚举值的名称? –
其实他们不是我的。这些类型来自几个Web服务引用。 – anilca