예제 #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);
                }
            }