Exemple #1
0
        public static Action <T, P>?CreateSetter <T, P>(MemberInfo m)
        {
            using (HeavyProfiler.LogNoStackTrace("CreateSetter"))
            {
                if (m is PropertyInfo pi && !pi.CanWrite)
                {
                    return(null);
                }

                ParameterExpression t = Expression.Parameter(typeof(T), "t");
                ParameterExpression p = Expression.Parameter(typeof(P), "p");

                var t2 = t.ConvertIfNeeded(m.DeclaringType !);
                var p2 = p.ConvertIfNeeded(m.ReturningType());

                var exp = Expression.Lambda(typeof(Action <T, P>), Expression.Assign(Expression.MakeMemberAccess(t2, m), p2), t, p);
                return((Action <T, P>)exp.Compile());
            }
        }