예제 #1
0
        public override Func <T, object> CreateGet <T>(PropertyInfo propertyInfo)
        {
            DynamicMethod dynamicMethod = DynamicReflectionDelegateFactory.CreateDynamicMethod("Get" + propertyInfo.Name,
                                                                                               typeof(object), new Type[1] {
                typeof(T)
            }, propertyInfo.DeclaringType);
            ILGenerator ilGenerator = dynamicMethod.GetILGenerator();

            this.GenerateCreateGetPropertyIL(propertyInfo, ilGenerator);
            return((Func <T, object>)dynamicMethod.CreateDelegate(typeof(Func <T, object>)));
        }
예제 #2
0
        public override Func <T> CreateDefaultConstructor <T>(Type type)
        {
            DynamicMethod dynamicMethod = DynamicReflectionDelegateFactory.CreateDynamicMethod("Create" + type.FullName,
                                                                                               typeof(T), ReflectionUtils.EmptyTypes, type);

            dynamicMethod.InitLocals = true;
            ILGenerator ilGenerator = dynamicMethod.GetILGenerator();

            this.GenerateCreateDefaultConstructorIL(type, ilGenerator, typeof(T));
            return((Func <T>)dynamicMethod.CreateDelegate(typeof(Func <T>)));
        }
예제 #3
0
        public override MethodCall <T, object> CreateMethodCall <T>(MethodBase method)
        {
            DynamicMethod dynamicMethod = DynamicReflectionDelegateFactory.CreateDynamicMethod(method.ToString(),
                                                                                               typeof(object), new Type[2] {
                typeof(object),
                typeof(object[])
            }, method.DeclaringType);
            ILGenerator ilGenerator = dynamicMethod.GetILGenerator();

            this.GenerateCreateMethodCallIL(method, ilGenerator, 1);
            return((MethodCall <T, object>)dynamicMethod.CreateDelegate(typeof(MethodCall <T, object>)));
        }
예제 #4
0
        public override ObjectConstructor <object> CreateParameterizedConstructor(
            MethodBase method)
        {
            DynamicMethod dynamicMethod = DynamicReflectionDelegateFactory.CreateDynamicMethod(method.ToString(),
                                                                                               typeof(object), new Type[1] {
                typeof(object[])
            }, method.DeclaringType);
            ILGenerator ilGenerator = dynamicMethod.GetILGenerator();

            this.GenerateCreateMethodCallIL(method, ilGenerator, 0);
            return((ObjectConstructor <object>)dynamicMethod.CreateDelegate(typeof(ObjectConstructor <object>)));
        }
예제 #5
0
        public override Action <T, object> CreateSet <T>(
            PropertyInfo propertyInfo)
        {
            DynamicMethod dynamicMethod = DynamicReflectionDelegateFactory.CreateDynamicMethod("Set" + propertyInfo.Name,
                                                                                               (Type)null, new Type[2] {
                typeof(T),
                typeof(object)
            }, propertyInfo.DeclaringType);
            ILGenerator ilGenerator = dynamicMethod.GetILGenerator();

            DynamicReflectionDelegateFactory.GenerateCreateSetPropertyIL(propertyInfo, ilGenerator);
            return((Action <T, object>)dynamicMethod.CreateDelegate(
                       typeof(Action <T, object>)));
        }
예제 #6
0
        public override Func <T, object> CreateGet <T>(FieldInfo fieldInfo)
        {
            if (fieldInfo.IsLiteral)
            {
                object constantValue = fieldInfo.GetValue((object)null);
                return((Func <T, object>)(o => constantValue));
            }

            DynamicMethod dynamicMethod = DynamicReflectionDelegateFactory.CreateDynamicMethod("Get" + fieldInfo.Name,
                                                                                               typeof(T), new Type[1] {
                typeof(object)
            }, fieldInfo.DeclaringType);
            ILGenerator ilGenerator = dynamicMethod.GetILGenerator();

            this.GenerateCreateGetFieldIL(fieldInfo, ilGenerator);
            return((Func <T, object>)dynamicMethod.CreateDelegate(typeof(Func <T, object>)));
        }