System.Yaml.Serialization.ReflectionUtils.CreateGetPropertyMethod C# (CSharp) Méthode

CreateGetPropertyMethod() public static méthode

generates a method to do 'return (object)(object.property);'
public static CreateGetPropertyMethod ( PropertyInfo propertyInfo ) : object>.Func
propertyInfo System.Reflection.PropertyInfo
Résultat object>.Func
        public static Func<object, object> CreateGetPropertyMethod(PropertyInfo propertyInfo)
        {
            ParameterExpression targParam = Expression.Parameter(typeof(object), "obj");

            //convert the parameter into the correct target type
            UnaryExpression target = Expression.Convert(targParam, propertyInfo.DeclaringType);
            //get the property
            MemberExpression fieldExp = Expression.Property(target, propertyInfo);
            //convert to object to return it
            UnaryExpression retConvExp = Expression.Convert(fieldExp, typeof(object));

            var finalLambda = Expression.Lambda<Func<object, object>>(retConvExp, targParam);

            return finalLambda.Compile();
        }