示例#1
0
        private Type GenerateCollectionProxyType(Type collectionType)
        {
            Type[] elementType = collectionType.GetGenericArguments();
            if (elementType.Length != 1)
            {
                throw new ArgumentException("Collection type should specify element type.");
            }

            Type baseListType = null;

            bool isSet     = collectionType.GetGenericTypeDefinition().Equals(typeof(IScalarSet <>));
            bool isOrdered = collectionType.GetGenericTypeDefinition().Equals(typeof(IOrderedCollection <>));

            if (!typesService.IsSealedType(elementType[0]))
            {
                if (!isSet)
                {
                    if (isOrdered)
                    {
                        baseListType = typeof(OrderedCollectionProxy <>);
                    }
                    else
                    {
                        baseListType = typeof(CollectionProxy <>);
                    }
                }
                else
                {
                    baseListType = typeof(SetCollectionProxy <>);
                }
            }
            else
            {
                if (!isSet)
                {
                    if (isOrdered)
                    {
                        baseListType = typeof(OrderedCollectionProxySealed <>);
                    }
                    else
                    {
                        baseListType = typeof(CollectionProxySealed <>);
                    }
                }
                else
                {
                    baseListType = typeof(SetCollectionProxySealed <>);
                }
            }

            return(baseListType.MakeGenericType(elementType));
        }