Beispiel #1
0
        public ILField CreateField(string fieldName, string targetName)
        {
            IILValue  target = Builders[targetName];
            FieldInfo field  = target.ValueType.GetField(fieldName, ALLATTR);

            return(new ILField(this.IL, field, target));
        }
Beispiel #2
0
        public ILProperty CreateProperty(string propertyName, string targetName)
        {
            IILValue     target   = Builders[targetName];
            PropertyInfo property = target.ValueType.GetProperty(propertyName, ALLATTR);

            return(new ILProperty(this.IL, property, target));
        }
Beispiel #3
0
        public ILMethod CreateMethod(string methodName, string targetName)
        {
            IILValue   target = Builders[targetName];
            MethodInfo method = target.ValueType.GetMethod(methodName, ALLATTR);

            return(new ILMethod(this.IL, method, target));
        }
Beispiel #4
0
        public ILMethod(ILGenerator il, MethodInfo obj, IILValue target)
            : base(il, ILType.Property)
        {
            base.obj       = obj;
            this.obj       = obj;
            this.target    = target;
            this.valueType = obj.ReturnType;

            Ld = delegate() { this.il.Emit(OpCodes.Call, (MethodInfo)obj); };
        }
Beispiel #5
0
        public void Return(IILValue value, params IILValue[] Parameters)
        {
            Type returnType = this.ddmethod.ReturnType;
            Type valueType  = value.ValueType;

            value.LdValue();

            convert(returnType, valueType);

            this.IL.Emit(OpCodes.Ret);
        }
Beispiel #6
0
 public ILObjectBase[] CreateArray(string arrayName, IILValue array)
 {
     throw new Exception("无法活动数组长度是个问题...");
     //LocalBuilder args = this.il.DeclareLocal(typeof(object[]));
     //this.il.Emit(OpCodes.Ldc_I4_1);
     //this.il.Emit(OpCodes.Newarr, typeof(object));
     //this.il.Emit(OpCodes.Stloc, args);
     //this.il.Emit(OpCodes.Ldloc, args);
     //this.il.Emit(OpCodes.Ldc_I4_0);
     //this.il.Emit(OpCodes.Ldloc, arg);
     //this.il.Emit(OpCodes.Stelem_Ref);
 }
Beispiel #7
0
        public ILProperty(ILGenerator il, PropertyInfo obj, IILValue target)
            : base(il, ILType.Property)
        {
            base.obj       = obj;
            this.obj       = obj;
            this.target    = target;
            this.valueType = obj.PropertyType;

            Ld = delegate()
            {
                this.il.Emit(OpCodes.Call, ((PropertyInfo)obj).GetGetMethod());
            };
        }
Beispiel #8
0
        public override LocalBuilder Call(IILValue array)
        {
            MethodInfo methodInfo = ((MethodInfo)obj);

            ParameterInfo[] paraInfos = methodInfo.GetParameters();
            LocalBuilder[]  paras     = new LocalBuilder[paraInfos.Length];

            Type elementType = array.ValueType.GetElementType();

            for (int i = 0; i < paraInfos.Length; i++)
            {
                paras[i] = this.il.DeclareLocal(paraInfos[i].ParameterType);
                array.LdValue();
                this.il.Emit(OpCodes.Ldc_I4, i);
                this.il.Emit(OpCodes.Ldelem_Ref);
                base.convert(paraInfos[i].ParameterType, elementType);
                this.il.Emit(OpCodes.Stloc, paras[i]);
            }

            if (methodInfo.IsStatic)
            {
                this.il.Emit(OpCodes.Ldnull);
            }
            else
            {
                this.target.LdValue();
            }

            for (int i = 0; i < paraInfos.Length; i++)
            {
                this.il.Emit(OpCodes.Ldloc, paras[i]);
            }

            LocalBuilder returnLocal = null;

            this.il.Emit(OpCodes.Call, methodInfo);

            if (methodInfo.ReturnType == typeof(void))
            {
            }
            else
            {
                returnLocal = il.DeclareLocal(methodInfo.ReturnType);
                this.il.Emit(OpCodes.Stloc, returnLocal);
            }
            return(returnLocal);
        }
Beispiel #9
0
        public ILField(ILGenerator il, FieldInfo obj, IILValue target)
            : base(il, ILType.Property)
        {
            base.obj       = obj;
            this.obj       = obj;
            this.target    = target;
            this.valueType = obj.FieldType;

            if (((FieldInfo)obj).IsStatic)
            {
                Ld = delegate() { this.il.Emit(OpCodes.Ldsfld, (FieldInfo)obj); }
            }
            ;
            else
            {
                Ld = delegate() { this.il.Emit(OpCodes.Ldfld, (FieldInfo)obj); }
            };
        }
Beispiel #10
0
        //新建对象实例
        /// <summary>
        /// 新建对象实例
        /// </summary>
        /// <param name="objType">对象类型</param>
        /// <param name="Parameters">构造函数参数</param>
        public void New(Type objType, params IILValue[] Parameters)
        {
            Type[]         argTypes   = new Type[Parameters.Length];
            LocalBuilder[] argBuilder = new LocalBuilder[Parameters.Length];

            for (int i = 0; i < Parameters.Length; i++)
            {
                IILValue v = Parameters[i];
                argTypes[i]   = v.ValueType;
                argBuilder[i] = v.StValue();
            }

            foreach (LocalBuilder var in argBuilder)
            {
                this.il.Emit(OpCodes.Ldloc, var);
            }

            this.il.Emit(OpCodes.Newobj, objType.GetConstructor(argTypes));
            //this.il.Emit(OpCodes.Stloc, ((LocalBuilder)(p0._arg)));
        }
Beispiel #11
0
        public ILProperty CreateProperty(string propertyName, IILValue target)
        {
            PropertyInfo property = target.ValueType.GetProperty(propertyName, ALLATTR);

            return(new ILProperty(this.IL, property, target));
        }
Beispiel #12
0
        public ILMethod CreateMethod(string methodName, IILValue target)
        {
            MethodInfo method = target.ValueType.GetMethod(methodName, ALLATTR);

            return(new ILMethod(this.IL, method, target));
        }
Beispiel #13
0
 public ILMethod CreateMethod(MethodInfo method, IILValue target)
 {
     return(new ILMethod(this.IL, method, target));
 }
Beispiel #14
0
        public ILField CreateField(string fieldName, IILValue target)
        {
            FieldInfo field = target.ValueType.GetField(fieldName, ALLATTR);

            return(new ILField(this.IL, field, target));
        }
Beispiel #15
0
 public ILField CreateField(FieldInfo field, IILValue target)
 {
     return(new ILField(this.IL, field, target));
 }
Beispiel #16
0
 public virtual LocalBuilder Call(IILValue Parameters)
 {
     throw new Exception("当前类不能使用此方法");
 }
Beispiel #17
0
 public ILProperty CreateProperty(PropertyInfo property, IILValue target)
 {
     return(new ILProperty(this.IL, property, target));
 }