public object Deserialize(Serializer serializer, Type staticType, Stream stream) { var underlyingType = Enum.GetUnderlyingType(staticType); IStaticTypeSerializer primitiveSerializer = serializer.GetTypeData(underlyingType).TypeSerializer; return(primitiveSerializer.Deserialize(serializer, underlyingType, stream)); }
public void Serialize(Serializer serializer, Type staticType, Stream stream, object ob) { var underlyingType = Enum.GetUnderlyingType(staticType); IStaticTypeSerializer primitiveSerializer = serializer.GetTypeData(underlyingType).TypeSerializer; primitiveSerializer.Serialize(serializer, underlyingType, stream, ob); }
// 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); }
void AddTypesInternal(Dictionary <Type, uint> typeMap) { foreach (var kvp in typeMap) { internalTypeCycles++; var type = kvp.Key; uint typeID = kvp.Value; if (type == null) { throw new ArgumentException("Null type in dictionary"); } if (typeID == 0) { throw new ArgumentException("TypeID 0 is reserved"); } if (m_runtimeTypeMap.ContainsKey(type)) { if (m_runtimeTypeMap[type].TypeID != typeID) { throw new ArgumentException(String.Format("Type {0} already added with different TypeID", type.FullName)); } continue; } if (m_runtimeTypeIDList.ContainsTypeID(typeID)) { throw new ArgumentException(String.Format("Type with typeID {0} already added", typeID)); } if (type.IsAbstract || type.IsInterface) { throw new ArgumentException(String.Format("Type {0} is abstract or interface", type.FullName)); } if (type.ContainsGenericParameters) { throw new NotSupportedException(String.Format("Type {0} contains generic parameters", type.FullName)); } IStaticTypeSerializer serializer = GetTypeSerializer(type); var data = new TypeData(type, typeID, serializer); m_runtimeTypeMap[type] = data; m_runtimeTypeIDList[typeID] = data; } }
Dictionary <Type, uint> AddTypesInternal(IEnumerable <Type> roots) { var stack = new Stack <Type>(roots); var addedMap = new Dictionary <Type, uint>(); while (stack.Count > 0) { internalTypeCycles++; var type = stack.Pop(); if (m_runtimeTypeMap.ContainsKey(type)) { continue; } if (type.ContainsGenericParameters) { throw new NotSupportedException(String.Format("Type {0} contains generic parameters", type.FullName)); } while (m_runtimeTypeIDList.ContainsTypeID(m_nextAvailableTypeID)) { m_nextAvailableTypeID++; } uint typeID = m_nextAvailableTypeID++; IStaticTypeSerializer serializer = GetTypeSerializer(type); var data = new TypeData(type, typeID, serializer); m_runtimeTypeMap[type] = data; m_runtimeTypeIDList[typeID] = data; addedMap[type] = typeID; foreach (var t in serializer.GetSubtypes(type)) { internalTypeCycles++; if (m_runtimeTypeMap.ContainsKey(t) == false) { stack.Push(t); } } } return(addedMap); }
public void Serialize(Serializer serializer, Type staticType, Stream stream, object ob) { if (ob == null) { Primitives.WritePrimitive(stream, (uint)0); } else { Type elementType = ob.GetType().GetElementType(); Array array = (Array)ob; int length = array.Length; Primitives.WritePrimitive(stream, (uint)length + 1); IStaticTypeSerializer typeSerializer = serializer.GetTypeData(elementType).TypeSerializer; foreach (object element in array) { typeSerializer.Serialize(serializer, elementType, stream, element); } } }
public object Deserialize(Serializer serializer, Type staticType, Stream stream) { uint lengthField; Primitives.ReadPrimitive(stream, out lengthField); if (lengthField == 0) { return(null); } else { uint length = lengthField - 1; Type elementType = staticType.GetElementType(); IStaticTypeSerializer typeSerializer = serializer.GetTypeData(elementType).TypeSerializer; var array = Array.CreateInstance(elementType, length); for (int i = 0; i < length; i++) { array.SetValue(typeSerializer.Deserialize(serializer, elementType, stream), i); } return(array); } }
public TypeData(Type type, uint typeID, IStaticTypeSerializer typeSerializer) { this.Type = type; this.TypeID = typeID; this.TypeSerializer = typeSerializer; }
public object Deserialize(Stream stream, Type type) { IStaticTypeSerializer serializer = GetTypeSerializer(type); return(serializer.Deserialize(this, type, stream)); }
public void Serialize(Stream stream, object value, Type type) { IStaticTypeSerializer serializer = GetTypeSerializer(type); serializer.Serialize(this, type, stream, value); }