简体   繁体   English

覆盖WCF DataMember的字典构造函数

[英]Override dictionary constructor for a WCF DataMember

Is it possible specify which constructor the WCF serialization engine uses when deserializing a data member? 反序列化数据成员时,可以指定WCF序列化引擎使用哪个构造函数吗?

For example: I want to use this constructor to make a case-insensitive dictionary without creating a new class that inherits from Dictionary. 例如:我想使用此构造函数来创建不区分大小写的字典,而无需创建从Dictionary继承的新类。

[DataMember]
Dictionary<string, string> Values { get; set; }

// Values should be created with this constructor
new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);

If you provide an implementation of your property setter method, you can instantiate for yourself the new case-insensitive Dictionary instance which will be the value of the property, and just copy into it the items from the instance provided by the serializer as the value parameter. 如果提供了属性设置器方法的实现,则可以为自己实例化新的不区分大小写的Dictionary实例,该实例将是属性的值,并且只需将序列化程序提供的实例中作为value参数的项目复制到其中即可。

You'll need to be prepared to handle any exceptions due to key clashes if the source of the serialized Dictionary was case-sensitive. 如果序列化Dictionary的源区分大小写,则需要准备处理由于键冲突而导致的任何异常。

Is it possible specify which constructor the WCF serialization engine uses when deserializing a data member? 反序列化数据成员时,可以指定WCF序列化引擎使用哪个构造函数吗?

No it isn't, unless you use implement your custom serialization. 不,不是,除非您使用实现自定义序列化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM