Ejemplo n.º 1
0
        public static MemberGetterDelegate MemberGetter(Type t, ClassMember member)
        {
            if (!GetterCache.TryGetValue(member.Member, out var getter))
            {
                var objParam = Parameter(typeof(object));

                GetterCache[member.Member] = getter = Lambda <MemberGetterDelegate>(Convert(Member(Convert(objParam, t), member), typeof(object)), objParam).Compile();
            }

            return(getter);
        }
Ejemplo n.º 2
0
        public static MemberSetterDelegate MemberSetter(Type t, ClassMember member)
        {
            if (!SetterCache.TryGetValue(member.Member, out var setter))
            {
                var objParam   = Parameter(typeof(object));
                var valueParam = Parameter(typeof(object));

                SetterCache[member.Member] = setter = Lambda <MemberSetterDelegate>(Assign(Member(Convert(objParam, t), member), Convert(valueParam, member.MemberType)), objParam, valueParam).Compile();
            }

            return(setter);
        }
Ejemplo n.º 3
0
        private static Expression Member(Expression inst, ClassMember member)
        {
            if (member.Member is PropertyInfo prop)
            {
                return(Property(inst, prop));
            }
            else if (member.Member is FieldInfo field)
            {
                return(Field(inst, field));
            }

            throw new Exception("Neither");
        }