在wcf中使用flag enumerations -尊龙游戏旗舰厅官网
请看msdn示例:
[datacontract][flags]
public enum carfeatures
{
none = 0,
[enummember]
airconditioner = 1,
[enummember]
automatictransmission = 2,
[enummember]
powerdoors = 4,
alloywheels = 8,
deluxepackage = airconditioner | automatictransmission | powerdoors | alloywheels,
[enummember]
cdplayer = 16,
[enummember]
tapeplayer = 32,
musicpackage = cdplayer | tapeplayer,
[enummember]
everything = deluxepackage | musicpackage
}
注意以下几点:
1. 请使用[flags]标志。
2.所有应用了enummemberattribute的枚举成员值必须是不间断的2的幂 (如 1, 2, 4, 8, 16, 32, 64).
3.如果通过数值来找枚举成员(比如通过4 来找powerdoors),会先判断是否存在这个成员,不存在则判断是否存在这样的组合成员,如果仍然不存在且数值不为0的话则会抛出serializationexception,如果数值为0则返回空列表。
4.未标记为[enummember]的成员,在wcf客户端不能使用,如上例中的none = 0。
详细用法请见msdn介绍。
http://msdn.microsoft.com/en-us/library/aa347875.aspx
you can use simple enumerations when you do not need to customize the enumeration's data contract name and namespace and the enumeration member values.
notes on simple enumerations
applying the enummemberattribute attribute to simple enumerations has no effect.
it makes no difference whether or not the serializableattribute attribute is applied to the enumeration.
the fact that the datacontractserializer class honors the nonserializedattribute attribute applied to enumeration members is different from the behavior of the binaryformatter and the soapformatter. both of those serializers ignore the nonserializedattribute attribute.
flag enumerations
you can apply the flagsattribute attribute to enumerations. in that case, a list of zero or more enumeration values can be sent or received simultaneously.
to do so, apply the datacontractattribute attribute to the flag enumeration and then mark all the members that are powers of two with the enummemberattribute attribute. note that to use a flag enumeration, the progression must be an uninterrupted sequence of powers of 2 (for example, 1, 2, 4, 8, 16, 32, 64).
the following steps apply to sending a flag's enumeration value:
转载于:https://www.cnblogs.com/furenjun/archive/2011/11/28/2265896.html
总结
以上是尊龙游戏旗舰厅官网为你收集整理的在wcf中使用flag enumerations的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: android自定义view研究(四)
- 下一篇: 模拟器上安装不能被卸载的apk