// Token: 0x06000388 RID: 904 RVA: 0x000132C0 File Offset: 0x000114C0
 internal void ResolveListTypes(Type type, ref Type itemType, ref Type defaultType)
 {
     if (type == null)
     {
         return;
     }
     if (Helpers.GetTypeCode(type) != ProtoTypeCode.Unknown)
     {
         return;
     }
     if (this[type].IgnoreListHandling)
     {
         return;
     }
     if (type.IsArray)
     {
         if (type.GetArrayRank() != 1)
         {
             throw new NotSupportedException("Multi-dimension arrays are supported");
         }
         itemType = type.GetElementType();
         if (itemType == base.MapType(typeof(byte)))
         {
             Type type2;
             itemType    = (type2 = null);
             defaultType = type2;
         }
         else
         {
             defaultType = type;
         }
     }
     if (itemType == null)
     {
         itemType = TypeModel.GetListItemType(this, type);
     }
     if (itemType != null)
     {
         Type type3 = null;
         Type type4 = null;
         this.ResolveListTypes(itemType, ref type3, ref type4);
         if (type3 != null)
         {
             throw TypeModel.CreateNestedListsNotSupported();
         }
     }
     if (itemType != null && defaultType == null)
     {
         if (type.IsClass && !type.IsAbstract && Helpers.GetConstructor(type, Helpers.EmptyTypes, true) != null)
         {
             defaultType = type;
         }
         if (defaultType == null && type.IsInterface)
         {
             Type[] genericArguments;
             if (type.IsGenericType && type.GetGenericTypeDefinition() == base.MapType(typeof(IDictionary <, >)) && itemType == base.MapType(typeof(KeyValuePair <, >)).MakeGenericType(genericArguments = type.GetGenericArguments()))
             {
                 defaultType = base.MapType(typeof(Dictionary <, >)).MakeGenericType(genericArguments);
             }
             else
             {
                 defaultType = base.MapType(typeof(List <>)).MakeGenericType(new Type[]
                 {
                     itemType
                 });
             }
         }
         if (defaultType != null && !Helpers.IsAssignableFrom(type, defaultType))
         {
             defaultType = null;
         }
     }
 }
Ejemplo n.º 2
0
        private static void ResolveListTypes(Type type, ref Type itemType, ref Type defaultType)
        {
            if (type == null)
            {
                return;
            }
            // handle arrays
            if (type.IsArray)
            {
                if (type.GetArrayRank() != 1)
                {
                    throw new NotSupportedException("Multi-dimension arrays are supported");
                }
                itemType = type.GetElementType();
                if (itemType == typeof(byte))
                {
                    defaultType = itemType = null;
                }
                else
                {
                    defaultType = type;
                }
            }
            // handle lists
            if (itemType == null)
            {
                itemType = TypeModel.GetListItemType(type);
            }

            // check for nested data (not allowed)
            if (itemType != null)
            {
                Type nestedItemType = null, nestedDefaultType = null;
                ResolveListTypes(itemType, ref nestedItemType, ref nestedDefaultType);
                if (nestedItemType != null)
                {
                    throw TypeModel.CreateNestedListsNotSupported();
                }
            }

            if (itemType != null && defaultType == null)
            {
                if (type.IsClass && !type.IsAbstract && type.GetConstructor(Helpers.EmptyTypes) != null)
                {
                    defaultType = type;
                }
                if (defaultType == null)
                {
                    if (type.IsInterface)
                    {
#if NO_GENERICS
                        defaultType = typeof(ArrayList);
#else
                        Type[] genArgs;
                        if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IDictionary <,>) &&
                            itemType == typeof(System.Collections.Generic.KeyValuePair <,>).MakeGenericType(genArgs = type.GetGenericArguments()))
                        {
                            defaultType = typeof(System.Collections.Generic.Dictionary <,>).MakeGenericType(genArgs);
                        }
                        else
                        {
                            defaultType = typeof(System.Collections.Generic.List <>).MakeGenericType(itemType);
                        }
#endif
                    }
                }
                // verify that the default type is appropriate
                if (defaultType != null && !type.IsAssignableFrom(defaultType))
                {
                    defaultType = null;
                }
            }
        }