Esempio n. 1
0
 private static ValueGetter GetValueGetter(object target, string name)
 {
     return(PropertyDescriptorValueGetter.GetPropertyDescriptorValueGetter(target, name)
            ?? GenericDictionaryValueGetter.GetGenericDictionaryValueGetter(target, name)
            ?? DictionaryValueGetter.GetDictionaryValueGetter(target, name)
            ?? MethodInfoValueGetter.GetMethodInfoValueGetter(target, name)
            ?? PropertyInfoValueGetter.GetPropertyInfoValueGetter(target, name)
            ?? FieldInfoValueGetter.GetFieldInfoValueGetter(target, name)
            ?? (ValueGetter) new NullValueGetter());
 }
        public void Visit(GenericDictionaryValueGetter getter)
        {
            var containsKeyMethod = getter.DictionaryType.GetMethod("ContainsKey");

            CompiledGetter = 
                Expression.Condition(
                    Expression.Call(_dataParameter, containsKeyMethod, Expression.Constant(getter.Key)),
                    Expression.Call(_dataParameter, getter.GetMethod, Expression.Constant(getter.Key)),
                    Expression.Default(getter.GetMethod.ReturnType));

        }