Esempio n. 1
0
        public static IKeyIndexed <string, ExpressionAccessor> Lookup(Type targetType)
        {
            Contract.Requires <ArgumentNullException>(targetType != null);
            Contract.Ensures(Contract.Result <IKeyIndexed <string, ExpressionAccessor> >() != null);

            lock (cache)
            {
                IKeyIndexed <string, IMemberAccessor> accessors;
                if (!cache.TryGetValue(targetType, out accessors))
                {
                    var props = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty)
                                .Select(pi => new ExpressionAccessor(pi));

                    var fields = targetType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.SetField)
                                 .Select(fi => new ExpressionAccessor(fi));

                    accessors = KeyIndexed.Create(props.Concat(fields), a => a.Name, a => a);
                    cache.Add(targetType, accessors);
                }
                ;

                Contract.Assume(accessors != null);
                return((IKeyIndexed <string, ExpressionAccessor>)accessors);
            }
        }
Esempio n. 2
0
        public static IKeyIndexed <string, ExpressionAccessor> Lookup(Type targetType)
        {
            lock (cache)
            {
                IKeyIndexed <string, IMemberAccessor> accessors;
                if (!cache.TryGetValue(targetType, out accessors))
                {
                    var props = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty)
                                .Select(pi => new ExpressionAccessor(pi));

                    var fields = targetType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.SetField)
                                 .Select(fi => new ExpressionAccessor(fi));

                    accessors = KeyIndexed.Create(props.Concat(fields), a => a.Name, a => a);
                    cache.Add(targetType, accessors);
                }
                ;

                return((IKeyIndexed <string, ExpressionAccessor>)accessors);
            }
        }