将未知的KeyValuePair对象转换为KeyValuePair <object,object =“”> </object,>

时间:2014-11-26 05:50:24

标签: c# generics casting converter keyvaluepair

我有一个类型为KeyValuePair<T1,T2>的对象,但实际的T1,T2类型只在运行时才知道。我想提取该对象的KeyValue,但我不知道如何。能否请你帮忙? (这个想法如下,但它不起作用)

public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer) {
     KeyValuePair<object, object> kvp = (KeyValuePair<object, object>)obj;
     Console.WriteLine("[{0},{1}]", kvp.Key, kvp.Value);
}

0 个答案:

没有答案