定义:
/// <summary>
/// The js function type(the same as name).
/// </summary>
[Flags]
public enum CallJSFunctionTypes
{
None = ,
ResetFixedBar = << ,
ResetRequiredField = << ,
SetValidateSuccessTextBoxStyle = << ,
SetValidateFailTextBoxStyle = << ,
ResizeSummary = <<
//,All = 1 << 6 - 1
}
使用:
//可以先给个初始值.
CallJSFunctionTypes JSFunctions = CallJSFunctionTypes.None; //... //可以这样赋值, 想包含什么意义, 就用"与"叠加.
JSFunctions = CallJSFunctionTypes.ResetFixedBar | CallJSFunctionTypes.ResetRequiredField | CallJSFunctionTypes.ResizeSummary; //... //判断是否包含某个意义
if ((JSFunctions & CallJSFunctionTypes.ResetFixedBar) == CallJSFunctionTypes.ResetFixedBar)
{
//Do something.
}
原理:
Int32 是 4字节32位二进制
None = 0,
即 0000 0000 0000 0000 0000 0000 0000 0000
ResetFixedBar = 1 << 1,
即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0000 0010
ResetRequiredField = 1 << 2,
即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0000 0100
SetValidateSuccessTextBoxStyle = 1 << 3,
即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0000 1000
SetValidateFailTextBoxStyle = 1 << 4,
即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0001 0000
ResizeSummary = 1 << 5,
即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0010 0000
All = 1 << 6 - 1
即 0000 0000 0000 0000 0000 0000 0010 0000 -> 0000 0000 0000 0000 0000 0000 0011 1111
赋值的时候:
ResetFixedBar|SetValidateSuccessTextBoxStyle|ResizeSummary
即
0000 0000 0000 0000 0000 0000 0000 0010
0000 0000 0000 0000 0000 0000 0000 1000
0000 0000 0000 0000 0000 0000 0010 0000
____________________________________
0000 0000 0000 0000 0000 0000 0010 1010
判断的时候:
判断有没有ResetFixedBar, 相"与"(&)
0000 0000 0000 0000 0000 0000 0010 1010
0000 0000 0000 0000 0000 0000 0000 0010
____________________________________
0000 0000 0000 0000 0000 0000 0000 0010 即ResetFixedBar, 即存在ResetFixedBar
判断有没有ResetRequiredField, 相"与"(&)
0000 0000 0000 0000 0000 0000 0010 1010
0000 0000 0000 0000 0000 0000 0000 0100
____________________________________
0000 0000 0000 0000 0000 0000 0000 0000 即不存在ResetFixedBar