Пример #1
0
        public static GetMemberDelegate GetEmit(PropertyInfo propertyInfo)
        {
            var getter = FieldInvoker.CreateDynamicGetMethod(propertyInfo);

            var gen = getter.GetILGenerator();

            gen.Emit(OpCodes.Ldarg_0);

            if (propertyInfo.DeclaringType.IsValueType)
            {
                gen.Emit(OpCodes.Unbox, propertyInfo.DeclaringType);
            }
            else
            {
                gen.Emit(OpCodes.Castclass, propertyInfo.DeclaringType);
            }

            var mi = propertyInfo.GetGetMethod(true);

            gen.Emit(mi.IsFinal ? OpCodes.Call : OpCodes.Callvirt, mi);

            if (propertyInfo.PropertyType.IsValueType)
            {
                gen.Emit(OpCodes.Box, propertyInfo.PropertyType);
            }

            gen.Emit(OpCodes.Ret);

            return((GetMemberDelegate)getter.CreateDelegate(typeof(GetMemberDelegate)));
        }
Пример #2
0
        public override SetMemberDelegate CreateSetter(FieldInfo fieldInfo)
        {
            return
                (#if NETSTANDARD2_0
                 SupportsEmit ? FieldInvoker.SetEmit(fieldInfo) :
#endif
                 SupportsExpression
                    ? FieldInvoker.SetExpression(fieldInfo)
                    : base.CreateSetter(fieldInfo));
        }
Пример #3
0
        public override GetMemberDelegate <T> CreateGetter <T>(FieldInfo fieldInfo)
        {
            return
                (#if NETSTANDARD2_0
                 SupportsEmit ? FieldInvoker.GetEmit <T>(fieldInfo) :
#endif
                 SupportsExpression
                    ? FieldInvoker.GetExpression <T>(fieldInfo)
                    : base.CreateGetter <T>(fieldInfo));
        }
Пример #4
0
        public static SetMemberDelegate SetEmit(PropertyInfo propertyInfo)
        {
            var mi = propertyInfo.GetSetMethod(true);

            if (mi == null)
            {
                return(null);
            }

            var setter = FieldInvoker.CreateDynamicSetMethod(propertyInfo);

            var gen = setter.GetILGenerator();

            gen.Emit(OpCodes.Ldarg_0);

            if (propertyInfo.DeclaringType.IsValueType)
            {
                gen.Emit(OpCodes.Unbox, propertyInfo.DeclaringType);
            }
            else
            {
                gen.Emit(OpCodes.Castclass, propertyInfo.DeclaringType);
            }

            gen.Emit(OpCodes.Ldarg_1);

            if (propertyInfo.PropertyType.IsValueType)
            {
                gen.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType);
            }
            else
            {
                gen.Emit(OpCodes.Castclass, propertyInfo.PropertyType);
            }

            gen.EmitCall(mi.IsFinal ? OpCodes.Call : OpCodes.Callvirt, mi, (Type[])null);

            gen.Emit(OpCodes.Ret);

            return((SetMemberDelegate)setter.CreateDelegate(typeof(SetMemberDelegate)));
        }
Пример #5
0
 public override SetMemberDelegate <T> CreateSetter <T>(FieldInfo fieldInfo)
 {
     return(SupportsExpression
         ? FieldInvoker.SetExpression <T>(fieldInfo)
         : base.CreateSetter <T>(fieldInfo));
 }