Пример #1
0
        private static object getValue(object o, DicBinding b)
        {
            Type   propType = o.GetType().GetProperty(b.PropName).PropertyType;
            object dic      = getPropertyValue(o, b.PropName);

            if (dic == null)
            {
                return(null);
            }
            Expression express =
                Expression.Call(Expression.Constant(dic),
                                // ReSharper disable once PossiblyMistakenUseOfParamsMethod
                                propType.GetMethod("get_Item"), Expression.Constant(b.Key));
            var    l   = Expression.Lambda(express);
            object res = null;

            try
            {
                res = l.Compile().DynamicInvoke();
            }
            catch (TargetInvocationException)
            {
            }

            return(res);
        }
Пример #2
0
        private static void setValue(object dest, DicBinding b, object val)
        {
            Type   propType = dest.GetType().GetProperty(b.PropName).PropertyType;
            object dic      = getPropertyValue(dest, b.PropName);

            if (dic == null)
            {
                return;
            }
            Expression express =
                Expression.Call(Expression.Constant(dic),
                                propType.GetMethod("Add"), Expression.Constant(b.Key), Expression.Constant(val));
            var l = Expression.Lambda(express);

            try
            {
                l.Compile().DynamicInvoke();
            }
            catch (ArgumentException)
            {
            }
        }