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