Exemple #1
0
        public EModel Dup()
        {
            ILGenerator il = ThreadCache.GetIL();

            il.Dup();
            return(EModel.CreateModelFromAction(null, _typeHandler));
        }
Exemple #2
0
 public static void BoolInStack(this ILGenerator il, Type type)
 {
     if (type == typeof(bool))
     {
         ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
     }
 }
Exemple #3
0
        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);
                }
            });
        }
Exemple #4
0
        public EMethod Execute(MethodInfo info, object[] instances)
        {
            ILGenerator il = ThreadCache.GetIL();

            if (instances != null)
            {
                for (int i = 0; i < instances.Length; i++)
                {
                    if (instances[i] != null)
                    {
                        il.NoErrorLoad(instances[i]);
                    }
                }
            }
            MethodHelper.CallMethod(info);
            if (info.ReturnType != null)
            {
                EMethod newMethod = info.ReturnType;
                return(newMethod);
            }
            else
            {
                return(null);
            }
        }
Exemple #5
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);
                }
            });
        }
Exemple #6
0
 public Func <Action, EJudge> ElseIf(object temp)
 {
     il.NoErrorLoad(temp);
     CurrentLabel = il.DefineLabel();
     LabelIndex  += 1;
     il.REmit(ThreadCache.GetJudgeCode(), CurrentLabel);
     return(TrueFunc);
 }
Exemple #7
0
 public static Action IsDBNull(Action action)
 {
     return(() => {
         ILGenerator il = ThreadCache.GetIL();
         action();
         il.REmit(OpCodes.Isinst, typeof(DBNull));
         ThreadCache.SetJudgeCode(OpCodes.Brfalse_S);
     });;
 }
Exemple #8
0
 public static Action IsDefault(Type type, Action action)
 {
     //加载对应类型的默认值
     return(() => {
         LoadDefault(type);
         action();
         ThreadCache.SetJudgeCode(OpCodes.Bne_Un_S);
     });
 }
Exemple #9
0
 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);
     });
 }
Exemple #10
0
        /// <summary>
        /// 提供while操作
        /// </summary>
        /// <param name="condition">判断语句</param>
        /// <returns></returns>
        public static Func <Action, ELoop> While(Action condition)
        {
            ELoop loopHandler = new ELoop();

            loopHandler.StartLabel = loopHandler.il.DefineLabel();
            loopHandler.EndLabel   = loopHandler.il.DefineLabel();
            loopHandler.il.MarkLabel(loopHandler.StartLabel);                        //设置开始标签
            condition();                                                             //条件判断
            loopHandler.il.REmit(ThreadCache.GetJudgeCode(), loopHandler.EndLabel);  //不成立就跳转到末尾
            return(loopHandler.BodyFunc);
        }
Exemple #11
0
        public static Func <Action, EJudge> If(Action action)
        {
            EJudge newEJudge = new EJudge();

            action?.Invoke();
            newEJudge.EndLabel     = newEJudge.il.DefineLabel();
            newEJudge.CurrentLabel = newEJudge.il.DefineLabel();
            newEJudge.LabelIndex  += 1;
            newEJudge.il.REmit(ThreadCache.GetJudgeCode(), newEJudge.CurrentLabel);
            return(newEJudge.TrueFunc);
        }
Exemple #12
0
        //其他跳转方式 已经由重载运算符完成
        public static Func <Action, EJudge> If(object temp)
        {
            EJudge newEJudge = new EJudge();

            newEJudge.il.NoErrorLoad(temp);
            newEJudge.EndLabel     = newEJudge.il.DefineLabel();
            newEJudge.CurrentLabel = newEJudge.il.DefineLabel();
            newEJudge.LabelIndex  += 1;
            newEJudge.il.REmit(ThreadCache.GetJudgeCode(), newEJudge.CurrentLabel);
            return(newEJudge.TrueFunc);
        }
Exemple #13
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);
 }
Exemple #14
0
        public static void CallMethod(MethodInfo info)
        {
            ILGenerator il = ThreadCache.GetIL();

            if (info.DeclaringType.IsValueType || info.IsStatic)
            {
                il.REmit(OpCodes.Call, info);
            }
            else
            {
                il.REmit(OpCodes.Callvirt, info);
            }
        }
Exemple #15
0
        public static void Packet(Type type, Action loadAction)
        {
            ILGenerator ilHandler = ThreadCache.GetIL();

            if (loadAction != null)
            {
                loadAction();
            }
            if (type.IsValueType)
            {
                ilHandler.Emit(OpCodes.Box, type);
            }
        }
Exemple #16
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);
         }
     });
 }
Exemple #17
0
        public static void UnPacket(Type type, Action loadAction)
        {
            ILGenerator ilHandler = ThreadCache.GetIL();

            if (loadAction != null)
            {
                loadAction();
            }
            if (type.IsClass && type != typeof(string) && type != typeof(object))
            {
                ilHandler.Emit(OpCodes.Castclass, type);
            }
            else
            {
                ilHandler.Emit(OpCodes.Unbox_Any, type);
            }
        }
Exemple #18
0
        public EMethod Execute(MethodInfo info, Action action = null)
        {
            ILGenerator il = ThreadCache.GetIL();

            if (action != null)
            {
                action();
            }
            MethodHelper.CallMethod(info);
            if (info.ReturnType != null)
            {
                EMethod newMethod = info.ReturnType;
                return(newMethod);
            }
            else
            {
                return(null);
            }
        }
Exemple #19
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);
        }
Exemple #20
0
 public static void UnPacket(Type type, object value)
 {
     UnPacket(type, () => { ThreadCache.GetIL().NoErrorLoad(value); });
 }
Exemple #21
0
 public static void LoadNull()
 {
     ThreadCache.GetIL().Emit(OpCodes.Ldnull);
 }
Exemple #22
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));
            }
        }
Exemple #23
0
 public static void LoadValue()
 {
     ThreadCache.GetIL().REmit(OpCodes.Ldsfld, Value);
 }
Exemple #24
0
 //压栈并返回
 public static void ReturnValue(object value)
 {
     ThreadCache.GetIL().NoErrorLoad(value);
     Return();
 }
Exemple #25
0
        //返回
        public static void Return()
        {
            ILGenerator il = ThreadCache.GetIL();

            il.REmit(OpCodes.Ret);
        }
Exemple #26
0
 public ILGeneratorBase()
 {
     //从线程缓存中获取IL
     il       = ThreadCache.GetIL();
     ThreadId = Thread.CurrentThread.ManagedThreadId;
 }
Exemple #27
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));
            }
        }
Exemple #28
0
 public static void Initialize()
 {
     ThreadCache.Initialize();
     ClassCache.Initialize();
 }
Exemple #29
0
        public void Pop()
        {
            ILGenerator il = ThreadCache.GetIL();

            il.Pop();
        }
Exemple #30
0
        public static void LoadDefault(Type type)
        {
            ILGenerator il = ThreadCache.GetIL();

            il.EmitDefault(type);
        }