示例#1
0
 public static void Dec(ILGenerator il, LocalBuilder local)
 {
     ILEmitHelper.LoadVar(il, local);
     il.Emit(OpCodes.Ldc_I4_1);
     il.Emit(OpCodes.Sub);
     ILEmitHelper.StormVar(il, local);
 }
示例#2
0
 public static void LoadField(ILGenerator il, FieldInfo field)
 {
     if (field.IsLiteral)
     {
         object value = field.GetValue(null);
         if (value is int)
         {
             ILEmitHelper.LoadInt(il, (int)value);
         }
         else if (value is float)
         {
             il.Emit(OpCodes.Ldc_R4, (float)value);
         }
         else if (value is string)
         {
             il.Emit(OpCodes.Ldstr, (string)value);
         }
         else if (value is bool)
         {
             bool bv = (bool)value;
             if (bv)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
         }
         else
         {
             throw new Exception("编译器不支持" + field.FieldType.Name + "类型");
         }
     }
     else if (field.IsStatic)
     {
         il.Emit(OpCodes.Ldsfld, field);
     }
     else
     {
         il.Emit(OpCodes.Ldfld, field);
     }
 }
示例#3
0
 public static void LoadDefaultValue(ILGenerator il, Type type)
 {
     if (type == typeof(bool))
     {
         il.Emit(OpCodes.Ldc_I4_0);
     }
     else if (type == typeof(int))
     {
         il.Emit(OpCodes.Ldc_I4_0);
     }
     else if (type == typeof(float))
     {
         il.Emit(OpCodes.Ldc_R4, (float)0.0);
     }
     else if (type == typeof(double))
     {
         il.Emit(OpCodes.Ldc_R8, (float)0.0);
     }
     else if (type == typeof(string))
     {
         il.Emit(OpCodes.Ldstr, "");
     }
     else if (type == typeof(char))
     {
         il.Emit(OpCodes.Ldc_I4_0);
     }
     else
     {
         ConstructorInfo constructor = type.GetConstructor(new Type[] { });
         if (constructor == null)
         {
             il.Emit(OpCodes.Ldnull);
         }
         else
         {
             ILEmitHelper.NewObj(il, constructor);
         }
     }
 }