有没有在.NET中的序列化的通用键/值对的类?序列化、NET

2023-09-02 10:24:18 作者:多情必自斃,無愛便是王

我正在寻找一个键/值对的对象,我可以包括一个Web服务。

I'm looking for a key/value pair object that I can include in a web service.

我试着使用.NET的System.Collections.Generic.KeyValuePair<>类,但它不正确序列中的web服务。在Web服务中,key和value属性不是序列化,使这一类无用的,除非有人知道一种方法来解决这个问题。

I tried using .NET's System.Collections.Generic.KeyValuePair<> class, but it does not properly serialize in a web service. In a web service, the Key and Value properties are not serialized, making this class useless, unless someone knows a way to fix this.

是否有可用于这种情况下的任何其他通用类?

Is there any other generic class that can be used for this situation?

我会使用.NET的System.Web.UI.Pair类,但它使用的对象为它的类型。这将是很好用一个通用类,如果仅仅是类型安全。

I'd use .NET's System.Web.UI.Pair class, but it uses Object for its types. It would be nice to use a Generic class, if only for type safety.

推荐答案

只要定义一个结构/类。

Just define a struct/class.

[Serializable]
public struct KeyValuePair<K,V>
{
  public K Key {get;set;}
  public V Value {get;set;}
}