示例#1
0
 public static void BoolInStack(this ILGenerator il, Type type)
 {
     if (type == typeof(bool))
     {
         ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
     }
 }
示例#2
0
        public static Action operator ==(EVar source, object dest)
        {
            return(() =>
            {
                ILGenerator il = source.il;
                source.RunCompareAction();
                if (source.TypeHandler.IsValueType && source.TypeHandler.IsPrimitive)
                {
                    ThreadCache.SetJudgeCode(OpCodes.Bne_Un_S);
                }
                else
                {
                    ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
                }
                if (dest is IOperator)
                {
                    ((IOperator)dest).RunCompareAction();
                }
                else
                {
                    il.NoErrorLoad(dest);
                }

                if (source.TypeHandler == typeof(string))
                {
                    source.il.REmit(OpCodes.Call, ClassCache.StringCompare);
                }
            });
        }
示例#3
0
文件: EModel.cs 项目: wcfylcf/Natasha
        public static Action operator !=(EModel source, object dest)
        {
            return(() =>
            {
                ILGenerator il = source.il;
                source.RunCompareAction();
                if (source.CompareType.IsValueType && source.CompareType.IsPrimitive)
                {
                    ThreadCache.SetJudgeCode(OpCodes.Beq_S);
                }
                else
                {
                    ThreadCache.SetJudgeCode(OpCodes.Brtrue_S);
                }
                if (dest is IOperator)
                {
                    ((IOperator)dest).RunCompareAction();
                }
                else
                {
                    il.NoErrorLoad(dest);
                }

                if (source.CompareType == typeof(string))
                {
                    source.il.REmit(OpCodes.Call, ClassCache.StringCompare);
                }
                else if (source.CompareType.IsClass || (source.CompareType.IsValueType && !source.CompareType.IsPrimitive))
                {
                    source.il.REmit(OpCodes.Call, ClassCache.ClassCompare);
                }
            });
        }
示例#4
0
文件: EJudge.cs 项目: wcfylcf/Natasha
 public static Action IsDBNull(Action action)
 {
     return(() => {
         ILGenerator il = ThreadCache.GetIL();
         action();
         il.REmit(OpCodes.Isinst, typeof(DBNull));
         ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
     });;
 }
示例#5
0
文件: EJudge.cs 项目: wcfylcf/Natasha
 public static Action IsDefault(Type type, Action action)
 {
     //加载对应类型的默认值
     return(() => {
         LoadDefault(type);
         action();
         ThreadCache.SetJudgeCode(OpCodes.Bne_Un_S);
     });
 }
示例#6
0
文件: EJudge.cs 项目: wcfylcf/Natasha
 public static Action IsNull(Action action)
 {
     return(() => {
         ILGenerator il = ThreadCache.GetIL();
         action();
         il.REmit(OpCodes.Ldnull);
         il.REmit(OpCodes.Call, ClassCache.ClassCompare);
         ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
     });
 }
示例#7
0
 internal static void EmitBoolean(this ILGenerator il, bool value)
 {
     if (value)
     {
         il.REmit(OpCodes.Ldc_I4_1);
     }
     else
     {
         il.REmit(OpCodes.Ldc_I4_0);
     }
     ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
 }
示例#8
0
 public static Action CreateCompareAction(this ILGenerator il, IOperator source, object dest, OpCode code)
 {
     return(() => {
         source.RunCompareAction();
         ThreadCache.SetJudgeCode(code);
         if (dest is IOperator)
         {
             ((IOperator)dest).RunCompareAction();
         }
         else
         {
             il.NoErrorLoad(dest);
         }
     });
 }
示例#9
0
        public ComplexType LFieldValue(string fieldName)
        {
            FieldInfo info = Struction.Fields[fieldName];
            Type type = info.FieldType;

            //静态字段
            if (info.IsStatic)
            {
                il.REmit(OpCodes.Ldsfld, info);
            }
            else
            {
                This();
                il.REmit(OpCodes.Ldfld, info);
            }
            //如果单独加载了bool类型的值
            if (type == typeof(bool))
            {
                ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
            }
            return EModel.CreateModelFromAction(null, type);
        }
示例#10
0
        public EModel LProperty(string propertyName, bool isLoadValue = false)
        {
            _currentMemeberName = propertyName;
            PropertyInfo pInfo = Struction.Properties[_currentMemeberName];
            MethodInfo   info  = pInfo.GetGetMethod(true);

            if (info == null)
            {
                throw new NullReferenceException("找不到" + propertyName + "属性的Get方法!");
            }
            CompareType = pInfo.PropertyType;

            CurrentCallOption = GetCurrentOption(_currentMemeberName);
            switch (PrewCallOption)
            {
            case LinkCallOption.Default:
                #region 第一次调用
                switch (CurrentCallOption)
                {
                case LinkCallOption.Public_Property_Value_Call:
                    This();
                    il.REmit(OpCodes.Call, info);
                    break;

                case LinkCallOption.Public_Static_Property_Value_Call:
                    il.REmit(OpCodes.Call, info);
                    break;

                case LinkCallOption.Public_Property_Ref_Call:
                    This();
                    il.REmit(OpCodes.Callvirt, info);
                    break;

                case LinkCallOption.Public_Static_Property_Ref_Call:
                    il.REmit(OpCodes.Call, info);
                    break;

                case LinkCallOption.Private_Property_Value_Call:
                case LinkCallOption.Private_Property_Ref_Call:
                    il.REmit(OpCodes.Ldtoken, pInfo.DeclaringType);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                    il.REmit(OpCodes.Ldstr, pInfo.Name);
                    il.REmit(OpCodes.Ldc_I4_S, 44);
                    il.REmit(OpCodes.Call, ClassCache.PropertyInfoGetter);
                    Load();
                    il.Packet(pInfo.DeclaringType);
                    il.REmit(OpCodes.Callvirt, ClassCache.PropertyValueGetter);
                    il.UnPacket(pInfo.PropertyType);
                    break;

                default:
                    break;
                }
                break;

                #endregion
            case LinkCallOption.Private_Ref_Call:
            case LinkCallOption.Public_Ref_Call:
                #region 前一次非特殊类型的链式调用
                if (CurrentCallOption == LinkCallOption.Private_Property_Value_Call || CurrentCallOption == LinkCallOption.Private_Property_Ref_Call)
                {
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.REmit(OpCodes.Ldtoken, pInfo.DeclaringType);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                    il.REmit(OpCodes.Ldstr, pInfo.Name);
                    il.REmit(OpCodes.Ldc_I4_S, 44);
                    il.REmit(OpCodes.Call, ClassCache.PropertyInfoGetter);
                    il.LoadBuilder(tempBuidler, false);
                    il.Packet(pInfo.DeclaringType);
                    il.REmit(OpCodes.Callvirt, ClassCache.PropertyValueGetter);
                    il.UnPacket(pInfo.PropertyType);
                }
                else if (CurrentCallOption == LinkCallOption.Public_Property_Value_Call)
                {
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.LoadBuilder(tempBuidler);
                    il.REmit(OpCodes.Call, info);
                }
                else
                {
                    il.REmit(OpCodes.Callvirt, info);
                }
                #endregion
                break;

            case LinkCallOption.Public_Value_Call:
                #region 前一次非特殊类型的链式调用
                if (CurrentCallOption == LinkCallOption.Private_Property_Value_Call || CurrentCallOption == LinkCallOption.Private_Property_Ref_Call)
                {
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.REmit(OpCodes.Ldtoken, pInfo.DeclaringType);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                    il.REmit(OpCodes.Ldstr, pInfo.Name);
                    il.REmit(OpCodes.Ldc_I4_S, 44);
                    il.REmit(OpCodes.Call, ClassCache.PropertyInfoGetter);
                    il.LoadBuilder(tempBuidler, false);
                    il.Packet(pInfo.DeclaringType);
                    il.REmit(OpCodes.Callvirt, ClassCache.PropertyValueGetter);
                    il.UnPacket(pInfo.PropertyType);
                }
                else
                {
                    il.REmit(OpCodes.Call, info);
                }
                break;

                #endregion
            case LinkCallOption.Private_Value_Call:
                #region 前一次为私有值类型的链式调用

                if (CurrentCallOption == LinkCallOption.Private_Property_Value_Call || CurrentCallOption == LinkCallOption.Private_Property_Ref_Call)
                {
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.REmit(OpCodes.Ldtoken, pInfo.DeclaringType);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                    il.REmit(OpCodes.Ldstr, pInfo.Name);
                    il.REmit(OpCodes.Ldc_I4_S, 44);
                    il.REmit(OpCodes.Call, ClassCache.PropertyInfoGetter);
                    il.LoadBuilder(tempBuidler, false);
                    il.Packet(pInfo.DeclaringType);
                    il.REmit(OpCodes.Callvirt, ClassCache.PropertyValueGetter);
                    il.UnPacket(pInfo.PropertyType);
                }
                else
                {
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.LoadBuilder(tempBuidler);
                    il.REmit(OpCodes.Call, info);
                }
                break;

                #endregion
            default:
                break;
            }
            PreCallType = CompareType;
            if (pInfo.PropertyType == typeof(bool))
            {
                ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
            }

            if (Struction.DelegateMethods.ContainsKey(_currentMemeberName))
            {
                return(il.GetLink((EModel)this, TypeHandler));
            }
            else
            {
                return(il.GetLink((EModel)this, CompareType));
            }
        }
示例#11
0
        public EModel LField(string fieldName, bool isLoadValue = false)
        {
            _currentMemeberName = fieldName;
            FieldInfo info = Struction.Fields[_currentMemeberName];

            CompareType = info.FieldType;

            CurrentCallOption = GetCurrentOption(_currentMemeberName);
            switch (PrewCallOption)
            {
            case LinkCallOption.Default:
                #region 第一次调用
                switch (CurrentCallOption)
                {
                case LinkCallOption.Public_Field_Value_Call:
                    This();
                    if (isLoadValue)
                    {
                        il.REmit(OpCodes.Ldfld, info);
                    }
                    else
                    {
                        il.REmit(OpCodes.Ldflda, info);
                    }
                    break;

                case LinkCallOption.Public_Static_Field_Value_Call:
                    if (isLoadValue)
                    {
                        il.REmit(OpCodes.Ldsfld, info);
                    }
                    else
                    {
                        il.REmit(OpCodes.Ldsflda, info);
                    }
                    break;

                case LinkCallOption.Public_Field_Ref_Call:
                    This();
                    il.REmit(OpCodes.Ldfld, info);
                    break;

                case LinkCallOption.Public_Static_Field_Ref_Call:
                    il.REmit(OpCodes.Ldsfld, info);
                    break;

                case LinkCallOption.Private_Field_Value_Call:
                case LinkCallOption.Private_Field_Ref_Call:
                    il.REmit(OpCodes.Ldtoken, info.DeclaringType);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                    il.REmit(OpCodes.Ldstr, info.Name);
                    il.REmit(OpCodes.Ldc_I4_S, 44);
                    il.REmit(OpCodes.Callvirt, ClassCache.FieldInfoGetter);
                    Load();
                    il.Packet(info.DeclaringType);
                    il.REmit(OpCodes.Callvirt, ClassCache.FieldValueGetter);
                    il.UnPacket(info.FieldType);
                    break;

                default:
                    break;
                }
                break;

                #endregion
            case LinkCallOption.Public_Ref_Call:
            case LinkCallOption.Private_Ref_Call:
            case LinkCallOption.Public_Value_Call:
                #region 前一次非特殊类型的链式调用
                switch (CurrentCallOption)
                {
                case LinkCallOption.Public_Field_Value_Call:
                    if (isLoadValue)
                    {
                        il.REmit(OpCodes.Ldfld, info);
                    }
                    else
                    {
                        il.REmit(OpCodes.Ldflda, info);
                    }
                    break;

                case LinkCallOption.Public_Static_Field_Value_Call:
                    if (isLoadValue)
                    {
                        il.REmit(OpCodes.Ldsfld, info);
                    }
                    else
                    {
                        il.REmit(OpCodes.Ldsflda, info);
                    }
                    break;

                case LinkCallOption.Public_Field_Ref_Call:
                    il.REmit(OpCodes.Ldfld, info);
                    break;

                case LinkCallOption.Public_Static_Field_Ref_Call:
                    il.REmit(OpCodes.Ldsfld, info);
                    break;

                case LinkCallOption.Private_Field_Value_Call:
                case LinkCallOption.Private_Field_Ref_Call:
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.REmit(OpCodes.Ldtoken, info.DeclaringType);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                    il.REmit(OpCodes.Ldstr, info.Name);
                    il.REmit(OpCodes.Ldc_I4_S, 44);
                    il.REmit(OpCodes.Callvirt, ClassCache.FieldInfoGetter);
                    il.LoadBuilder(tempBuidler, false);
                    il.Packet(info.DeclaringType);
                    il.REmit(OpCodes.Callvirt, ClassCache.FieldValueGetter);
                    il.UnPacket(info.FieldType);
                    break;

                default:
                    break;
                }
                break;

                #endregion
            case LinkCallOption.Private_Value_Call:
                #region 前一次为私有值类型的链式调用

                if (CurrentCallOption == LinkCallOption.Private_Field_Value_Call || CurrentCallOption == LinkCallOption.Private_Field_Ref_Call)
                {
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.REmit(OpCodes.Ldtoken, info.DeclaringType);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                    il.REmit(OpCodes.Ldstr, info.Name);
                    il.REmit(OpCodes.Ldc_I4_S, 44);
                    il.REmit(OpCodes.Callvirt, ClassCache.FieldInfoGetter);
                    il.LoadBuilder(tempBuidler, false);
                    il.Packet(info.DeclaringType);
                    il.REmit(OpCodes.Callvirt, ClassCache.FieldValueGetter);
                    il.UnPacket(info.FieldType);
                }
                else
                {
                    LocalBuilder tempBuidler = il.DeclareLocal(PreCallType);
                    il.EmitStoreBuilder(tempBuidler);
                    il.LoadBuilder(tempBuidler);
                    switch (CurrentCallOption)
                    {
                    case LinkCallOption.Public_Field_Value_Call:
                        if (isLoadValue)
                        {
                            il.REmit(OpCodes.Ldfld, info);
                        }
                        else
                        {
                            il.REmit(OpCodes.Ldflda, info);
                        }
                        break;

                    case LinkCallOption.Public_Static_Field_Value_Call:
                        if (isLoadValue)
                        {
                            il.REmit(OpCodes.Ldsfld, info);
                        }
                        else
                        {
                            il.REmit(OpCodes.Ldsflda, info);
                        }
                        break;

                    case LinkCallOption.Public_Field_Ref_Call:
                        il.REmit(OpCodes.Ldfld, info);
                        break;

                    case LinkCallOption.Public_Static_Field_Ref_Call:
                        il.REmit(OpCodes.Ldsfld, info);
                        break;

                    default:
                        break;
                    }
                }

                break;

                #endregion
            default:
                break;
            }
            PreCallType = CompareType;
            if (info.FieldType == typeof(bool))
            {
                ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
            }
            if (Struction.DelegateMethods.ContainsKey(_currentMemeberName))
            {
                return(il.GetLink((EModel)this, TypeHandler));
            }
            else
            {
                return(il.GetLink((EModel)this, CompareType));
            }
        }