コード例 #1
0
        public static ConcurrentDictionary <string, Tuple <Func <object, object>, SetValueDelegate> > GetTypeGetterSetter(Type type)
        {
            ConcurrentDictionary <string, Tuple <Func <object, object>, SetValueDelegate> > value = null;

            if (!metas.ContainsKey(type))
            {
                lock (metas)
                {
                    if (metas.ContainsKey(type))
                    {
                        value = metas[type];
                    }
                    else
                    {
                        value = new ConcurrentDictionary <string, Tuple <Func <object, object>, SetValueDelegate> >();
                        metas.TryAdd(type, value);
                    }
                }
            }
            else
            {
                value = metas[type];
            }
            if (value.Count > 0)
            {
                return(value);
            }
            lock (value)
            {
                if (value.Count > 0)
                {
                    return(value);
                }
                type.GetProperties().ToList().ForEach(e =>
                {
                    var setter = FastInvoke.CreatePropertySetter(e);
                    var getter = FastInvoke.EmitGetter(e);
                    value.TryAdd(e.Name, new Tuple <Func <object, object>, SetValueDelegate>(getter, setter));
                });
            }
            return(value);
        }