WCF CollectionDataContract 字典构造函数
WCF CollectionDataContract Dictionary constructor
我正在使用 WCF CollectionDataContract
通过 Dictionary
传递数据,它工作得很好。
[CollectionDataContract]
public class MyDataDictionary : Dictionary<string, MyItemValue> { }
[DataContract]
public class MyItemValue
{
[DataMember] public int ID { get; set; }
[DataMember] public string Name { get; set; }
// ...
public IP21ItemValue() {
ID = -1;
Name = string.Empty;
// ...
}
}
我想增强我的字典,使其不区分大小写,我已经尝试了多种类似的方法:
// Attempt to put the argument on the declaration.
[CollectionDataContract]
public class MyDataDictionary : Dictionary<string, MyItemValue>(StringComparer.InvariantCultureIgnoreCase) { }
// Attempt to instantiate it within the constructor...
[CollectionDataContract]
public class MyDataDictionary : Dictionary<string, MyItemValue> {
public MyDataDictionary() {
this = new Dictionary<string, MyItemValue>(StringComparer.InvariantCultureIgnoreCase);
}
}
但我似乎无能为力。我真的很想避免将整个内容包装在字典是数据成员的 class 中。有没有语法可以做到这一点?
调用基本 class 构造函数,如下所示:
public class MyDataDictionary : Dictionary<string, MyItemValue> {
public MyDataDictionary()
:base(StringComparer.InvariantCultureIgnoreCase)
{
}
}
我正在使用 WCF CollectionDataContract
通过 Dictionary
传递数据,它工作得很好。
[CollectionDataContract]
public class MyDataDictionary : Dictionary<string, MyItemValue> { }
[DataContract]
public class MyItemValue
{
[DataMember] public int ID { get; set; }
[DataMember] public string Name { get; set; }
// ...
public IP21ItemValue() {
ID = -1;
Name = string.Empty;
// ...
}
}
我想增强我的字典,使其不区分大小写,我已经尝试了多种类似的方法:
// Attempt to put the argument on the declaration.
[CollectionDataContract]
public class MyDataDictionary : Dictionary<string, MyItemValue>(StringComparer.InvariantCultureIgnoreCase) { }
// Attempt to instantiate it within the constructor...
[CollectionDataContract]
public class MyDataDictionary : Dictionary<string, MyItemValue> {
public MyDataDictionary() {
this = new Dictionary<string, MyItemValue>(StringComparer.InvariantCultureIgnoreCase);
}
}
但我似乎无能为力。我真的很想避免将整个内容包装在字典是数据成员的 class 中。有没有语法可以做到这一点?
调用基本 class 构造函数,如下所示:
public class MyDataDictionary : Dictionary<string, MyItemValue> {
public MyDataDictionary()
:base(StringComparer.InvariantCultureIgnoreCase)
{
}
}