Пример #1
0
            public static GenericCollection GetList(Type type)
            {
                GenericCollection list;

                if (_Cache.TryGetValue(type, out list))
                {
                    return(list);
                }
                if (type.GetInterface("System.Collections.IList") != typeof(IList))
                {
                    return(null);
                }
                lock (_Cache)
                {
                    if (_Cache.TryGetValue(type, out list))
                    {
                        return(list);
                    }
                    list      = new GenericCollection();
                    list.Init = Literacy.CreateNewObject(type);
                    if (type.IsGenericType)
                    {
                        list.ElementType = type.GetGenericArguments()[0];
                        list.ElementType = Nullable.GetUnderlyingType(list.ElementType) ?? list.ElementType;
                    }
                    else
                    {
                        list.ElementType = typeof(object);
                    }
                    _Cache.Add(type, list);
                    return(list);
                }
            }
Пример #2
0
            public static GenericCollection GetDict(Type type)
            {
                GenericCollection dict;

                if (_Cache.TryGetValue(type, out dict))
                {
                    return(dict);
                }
                lock (_Cache)
                {
                    if (_Cache.TryGetValue(type, out dict))
                    {
                        return(dict);
                    }
                    dict      = new GenericCollection();
                    dict.Init = Literacy.CreateNewObject(type);
                    if (type.IsGenericType)
                    {
                        var ga = type.GetGenericArguments();
                        if (ga.Length > 1)
                        {
                            dict.KeyType     = type.GetGenericArguments()[0];
                            dict.ElementType = type.GetGenericArguments()[1];
                            dict.ElementType = Nullable.GetUnderlyingType(dict.ElementType) ?? dict.ElementType;
                        }
                        else
                        {
                            dict.ElementType = typeof(object);
                        }
                    }
                    else
                    {
                        dict.ElementType = typeof(object);
                    }
                    _Cache.Add(type, dict);
                    return(dict);
                }
            }