“KeyValuePair”的序列化
有一个朋友提到:KeyValuePair默认不能被序列化,你须要自定义一个KeyValuePair并将其标志为[Serializable]” ,在这里再次谢谢他,谢谢。
问题一:应该怎样自定义呢??? “KeyValuePair”类型作为“服务接口方法的参数”会报错,但是作为实体类的属性没有问题。
实体对象属性如下:
public KeyValuePair<Period, string> Date
{
get; set;
}
服务接口方法:
public List<Monitoring> GetMonitoringEntityData(Monitoring.EnergyType energytype, KeyValuePair<Monitoring.Period, string> monitordate,KeyValuePair<Monitoring.MonitorType, string> monitortype, string meterusetype, bool issubstation)
问题二:
“NET简单类型,你可以使用Serializable属性,这些你就不须要显示定义DataContract了,其它的复杂类型(例如类中还包含有其它自定类型的属性时),这时我就要使用DataContract与DataMember来显示标记类与属性等”
“Serializable属性”怎么被使用的???什么也没做啊?
是不是
[SerializableAttribute]
[ComVisibleAttribute(true)]
publicsealedclass String : IComparable,
ICloneable, IConvertible, IComparable<string>, IEnumerable<char>,
IEnumerable, IEquatable<string>
[SerializableAttribute]
public struct KeyValuePair<TKey, TValue>
是不是“SerializableAttribute” 标记??? “KeyValuePair”和“String”类型都有啊。。。
[解决办法]