Пример #1
0
        public static Func <TField> StaticGetField <TField>(FieldInfo field)
        {
            DynamicMethod getter = new DynamicMethod($"get_{field.DeclaringType.Name}_{field.Name}", typeof(TField), new Type[] { }, typeof(Dynamic), true);
            IILGenerator  gen    = getter.GetILGenerator().AsInterface();

            gen
            .Ldsfld(field)
            .Ret();

            return((Func <TField>)getter.CreateDelegate(typeof(Func <TField>)));
        }