Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public static void AddSerializer(TagSerializer serializer)
 {
     TagSerializer.serializers.Add(serializer.Type, serializer);
 }
Esempio n. 4
0
 static TagSerializer()
 {
     TagSerializer.Reload();
 }