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