【发布时间】:2011-06-10 18:56:58
【问题描述】:
我有这个:
public static void Remove<T>(string controlID) where T: new()
{
Logger.InfoFormat("Removing control {0}", controlID);
T states = RadControlStates.GetStates<T>();
//Not correct.
(states as SerializableDictionary<string, object>).Remove(controlID);
RadControlStates.SetStates<T>(states);
}
states 将始终是带有字符串键的 SerializableDictionary。值的类型各不相同。有没有办法表达这个?转换为 SerializableDictioanry<string, object> 总是产生 null。
【问题讨论】:
-
RadControlStates.GetStates是如何定义的?如果as运算符返回null,那不是你想的那样。 -
同意。只是以为我可以将所有类型转换为“对象”,但那太愚蠢了。
标签: c# refactoring templating