【发布时间】:2014-08-04 06:54:54
【问题描述】:
要求是这样的。现在我有了字典。
Dictionary<int,string> dic = new Dictionary<int,string>();
//... some other operations
Type t = typeof(Dictionary<int,string>);
现在我想获取类型 int 和 string。我怎样才能得到这两个?非常感谢。
更新:
感谢您的回复。实际上我的要求是基于从字典类型获得的两种类型创建另一个泛型类。就这样。
PropertyType propertyType = typeof(Dictionary<int,string>);
if (propertyType.Name.Contains("Dictionary"))
{
Type keyType = propertyType.GetGenericArguments()[0];
Type valueType = propertyType.GetGenericArguments()[1];
propertyType = typeof(SerializableDictionary<keyType, valueType>);
}
//And after this, it will dynamically create a class and add the propery as one
//of its properties
现在我不能使用propertyType = typeof(SerializableDictionary<keyType, valueType>)。我应该如何更新此声明?谢谢。
【问题讨论】:
标签: c#