il code swtich
public enum RangeItemType { CompanyPicker = 1, //公司STR_COMPANY BrDivPicker = 2, //分行STR_BRDIV DepartPicker = 3, //部门STR_DEPARTMENT SectionPicker = 4, //科组STR_SECTION PositionPicker = 5, //职位STR_POSITION CategoryPicker = 6, //级别STR_CATEGORY StaffPicker = 7, //雇员STR_STAFF GradePicker = 8, //职级STR_GRADE RankPicker = 9, //职阶STR_RANK } switch (key) { #region Range控件 case RangeItemType.StaffPicker: //雇员 case RangeItemType.CompanyPicker: //公司 case RangeItemType.BrDivPicker: //分行 case RangeItemType.DepartPicker: //部门 case RangeItemType.SectionPicker: //科组 case RangeItemType.PositionPicker: //职位 case RangeItemType.CategoryPicker: //级别 case RangeItemType.GradePicker: //职级 case RangeItemType.RankPicker: //职阶 case RangeItemType.ContractTermsPicker: //合约条件 case RangeItemType.PayTermsPicker: //支薪条件 case RangeItemType.MedBenefitPolicyPicker: //医疗福利政策 case RangeItemType.OrgLevel1Picker: //组织层级1 case RangeItemType.OrgLevel2Picker: //组织层级2 case RangeItemType.OrgLevel3Picker: //组织层级3 case RangeItemType.OrgLevel4Picker: //组织层级4 case RangeItemType.OrgLevel5Picker: //组织层级5 case RangeItemType.OrgLevel6Picker: //组织层级6 case RangeItemType.OrgLevel7Picker: //组织层级7 case RangeItemType.OrgLevel8Picker: //组织层级8 case RangeItemType.OrgLevel9Picker: //组织层级9 case RangeItemType.OrgLevel10Picker: //组织层级10 case RangeItemType.OrgLevel11Picker: //组织层级11 case RangeItemType.OrgLevel12Picker: //组织层级12 case RangeItemType.OrgUnitPicker: //组织层级12 _returnVal = RangeClassType.RangePicker; break;
生成 il
IL_0010: ldloc.2
IL_0011: ldc.i4 11013
IL_0016: bgt IL_00a4
IL_001b: ldloc.2
IL_001c: ldc.i4.1
IL_001d: sub
IL_001e: switch (IL_0116, IL_0116, IL_0116, IL_0116, IL_0116, IL_0116, IL_0116, IL_0116, IL_0116)
。。。。。。
IL_0116: ldc.i4.1
IL_0117: stloc.0
IL_0118: br.s IL_012a
感觉用Sub和Switch很神奇
改成 CategoryPicker 单独 拿出来
switch (key) { case RangeItemType.CompanyPicker: case RangeItemType.BrDivPicker: case RangeItemType.DepartPicker: case RangeItemType.SectionPicker: case RangeItemType.PositionPicker: case RangeItemType.StaffPicker: case RangeItemType.GradePicker: case RangeItemType.RankPicker: break; case RangeItemType.CategoryPicker: return result;
il 就生成了
IL_001e: switch (IL_0116, IL_0116, IL_0116, IL_0116, IL_0116, IL_012a, IL_0116, IL_0116, IL_0116)
就变了一个 IL_012a,
不过 RangeItemType 项目 编号不连续的话,就会就变成两个 Swtich
另外 dotPeek反编译出来比较对,和源码一样。
ilspy 反编译出来变成 switch和if互相套用,有点乱