public Type Get(SerializedTypes serializedTypes) { var genericType = type.Get(serializedTypes); var types = new List <Type>(genericArgs.Length); foreach (var ga in genericArgs) { types.Add(ga.Get(serializedTypes)); } return(genericType.MakeGenericType(types.ToArray())); }
private SerializedTypeDesc GetExistingTypeDesc(Type type) { SerializedTypeDesc typeDesc = new SerializedTypeDesc { TypeHandle = type.TypeHandle }; if (SerializedTypes.ContainsKey(typeDesc.SafeFullName)) { return(SerializedTypes[typeDesc.SafeFullName]); } SerializedTypes.Add(typeDesc.SafeFullName, typeDesc); return(typeDesc); }
// Walks through all the fields and gather types for subtype also private void GatherAllUsedTypesForType(Type type) { // Preprocess full name only SerializedTypeDesc typeDesc = new SerializedTypeDesc { TypeHandle = type.TypeHandle }; // We analyse type once only ... if (SerializedTypes.ContainsKey(typeDesc.SafeFullName)) { return; } // Type registration typeDesc = GetExistingTypeDesc(type); // Member fields inspection FieldInfo[] serializableMembers = (FieldInfo[])GetSerializableMembers(type); Array.ForEach(serializableMembers, field => { GatherAllUsedTypesForType(field.FieldType); if (field.FieldType.IsArray) { GatherAllUsedTypesForType(field.FieldType.GetElementType()); } }); // Does it have any serialization attributes? Type[] otherTypes = GetTypesFromSerializationAttributesOfTypeMembers(type); Array.ForEach(otherTypes, otherType => { GatherAllUsedTypesForType(otherType); if (otherType.IsArray) { GatherAllUsedTypesForType(otherType.GetElementType()); } }); }