System.Reflection.DynamicMethodCompiler.CreateGetterDelegate C# (CSharp) Method

CreateGetterDelegate() public static method

Creates the getter delegate.
public static CreateGetterDelegate ( Type type, PropertyInfo propertyInfo ) : GetterDelegate
type Type The type.
propertyInfo PropertyInfo The property info.
return GetterDelegate
        public static GetterDelegate CreateGetterDelegate(Type type, PropertyInfo propertyInfo)
        {
            MethodInfo getMethodInfo = propertyInfo.GetGetMethod(true);
            #if !CompactFramework
            DynamicMethod dynamicGet = CreateDynamicGetMethod(type);
            ILGenerator getGenerator = dynamicGet.GetILGenerator();

            getGenerator.Emit(OpCodes.Ldarg_0);
            getGenerator.Emit(OpCodes.Call, getMethodInfo);
            BoxIfNeeded(getMethodInfo.ReturnType, getGenerator);
            getGenerator.Emit(OpCodes.Ret);

            return (GetterDelegate)dynamicGet.CreateDelegate(typeof(GetterDelegate));
            #else
            return (obj) => getMethodInfo.Invoke(obj, null);
            #endif
        }

Same methods

DynamicMethodCompiler::CreateGetterDelegate ( Type type, FieldInfo fieldInfo ) : GetterDelegate