Beispiel #1
0
        // Token: 0x060000CE RID: 206 RVA: 0x00006ABC File Offset: 0x00004CBC
        private Dictionary <Type, TypeData> GenerateTypeData(IEnumerable <Type> rootTypes)
        {
            Dictionary <Type, TypeData> dictionary = new Dictionary <Type, TypeData>();
            Stack <Type> stack = new Stack <Type>(PrimitivesSerializer.GetSupportedTypes().Concat(rootTypes));

            stack.Push(typeof(object));
            ushort num = 1;

            while (stack.Count > 0)
            {
                Type type = stack.Pop();
                if (!dictionary.ContainsKey(type) && !type.IsAbstract && !type.IsInterface)
                {
                    if (type.ContainsGenericParameters)
                    {
                        throw new NotSupportedException(string.Format("Type {0} contains generic parameters", type.FullName));
                    }
                    ITypeSerializer typeSerializer = this.m_userTypeSerializers.FirstOrDefault((ITypeSerializer h) => h.Handles(type));
                    if (typeSerializer == null)
                    {
                        typeSerializer = Serializer.s_typeSerializers.FirstOrDefault((ITypeSerializer h) => h.Handles(type));
                    }
                    if (typeSerializer == null)
                    {
                        throw new NotSupportedException(string.Format("No serializer for {0}", type.FullName));
                    }
                    foreach (Type item in typeSerializer.GetSubtypes(type))
                    {
                        stack.Push(item);
                    }
                    TypeData value;
                    if (typeSerializer is IStaticTypeSerializer)
                    {
                        IStaticTypeSerializer staticTypeSerializer = (IStaticTypeSerializer)typeSerializer;
                        MethodInfo            writer;
                        MethodInfo            reader;
                        staticTypeSerializer.GetStaticMethods(type, out writer, out reader);
                        ushort num2 = num;
                        num   = num2 + 1;
                        value = new TypeData(num2, writer, reader);
                    }
                    else
                    {
                        if (!(typeSerializer is IDynamicTypeSerializer))
                        {
                            throw new Exception();
                        }
                        IDynamicTypeSerializer serializer = (IDynamicTypeSerializer)typeSerializer;
                        ushort num3 = num;
                        num   = num3 + 1;
                        value = new TypeData(num3, serializer);
                    }
                    dictionary[type] = value;
                }
            }
            return(dictionary);
        }
Beispiel #2
0
        Dictionary <Type, TypeData> GenerateTypeData(IEnumerable <Type> rootTypes)
        {
            var map   = new Dictionary <Type, TypeData>();
            var stack = new Stack <Type>(PrimitivesSerializer.GetSupportedTypes().Concat(rootTypes));

            stack.Push(typeof(object));

            // TypeID 0 is reserved for null
            ushort typeID = 1;

            while (stack.Count > 0)
            {
                var type = stack.Pop();

                if (map.ContainsKey(type))
                {
                    continue;
                }

                if (type.IsAbstract || type.IsInterface)
                {
                    continue;
                }

                if (type.ContainsGenericParameters)
                {
                    throw new NotSupportedException(String.Format("Type {0} contains generic parameters", type.FullName));
                }

                var serializer = m_userTypeSerializers.FirstOrDefault(h => h.Handles(type));

                if (serializer == null)
                {
                    serializer = s_typeSerializers.FirstOrDefault(h => h.Handles(type));
                }

                if (serializer == null)
                {
                    throw new NotSupportedException(String.Format("No serializer for {0}", type.FullName));
                }

                foreach (var t in serializer.GetSubtypes(type))
                {
                    stack.Push(t);
                }

                TypeData typeData;

                if (serializer is IStaticTypeSerializer)
                {
                    var sts = (IStaticTypeSerializer)serializer;

                    MethodInfo writer;
                    MethodInfo reader;

                    sts.GetStaticMethods(type, out writer, out reader);

                    Debug.Assert(writer != null && reader != null);

                    typeData = new TypeData(typeID++, writer, reader);
                }
                else if (serializer is IDynamicTypeSerializer)
                {
                    var dts = (IDynamicTypeSerializer)serializer;

                    typeData = new TypeData(typeID++, dts);
                }
                else
                {
                    throw new Exception();
                }

                map[type] = typeData;
            }

            return(map);
        }