public override T Deserialize(SharpTag tag) { if (tag.ContainsKey("<type>") && tag.GetString("<type>") != Type.FullName) { Type type = TagSerializer.GetType(tag.GetString("<type>")); if (type != null && Type.IsAssignableFrom(type) && TagSerializer.TryGetSerializer(type, out TagSerializer serializer)) { return((T)serializer.Deserialize(tag)); } } if (deserializer == null) { throw new ArgumentException(string.Format("Missing deserializer for type '{0}'", Type.FullName)); } return(deserializer(tag)); }
public static bool TryGetSerializer(Type type, out TagSerializer serializer) { if (TagSerializer.serializers.TryGetValue(type, out serializer)) { return(true); } if (typeof(TagSerializable).IsAssignableFrom(type)) { Type type2 = typeof(TagSerializableSerializer <>).MakeGenericType(new Type[] { type }); IDictionary <Type, TagSerializer> dict = TagSerializer.serializers; TagSerializer value; serializer = (value = (TagSerializer)type2.GetConstructor(new Type[0]).Invoke(new object[0])); dict[type] = value; return(true); } return(false); }
public static void AddSerializer(TagSerializer serializer) { TagSerializer.serializers.Add(serializer.Type, serializer); }
static TagSerializer() { TagSerializer.Reload(); }