Ejemplo n.º 1
0
        private static void AddBaseType(Type type, SerializeMethod serializeMethod, ParseMethod parseMethod)
        {
            if (IsBaseType(type))
            {
                throw new Exception($"Type {type} is already a supported base type. You cannot re-add it.");
            }

            BaseSerializeMethods.Add(type, serializeMethod);
            BaseParseMethods.Add(type, parseMethod);
        }
Ejemplo n.º 2
0
 /// <summary> Returns true if the type is a base type. </summary>
 public static bool IsBaseType(Type type)
 {
     if (type.IsEnum)
     {
         return(true);
     }
     if (BaseSerializeMethods.ContainsKey(type))
     {
         return(true);
     }
     if (BaseStyledSerializeMethods.ContainsKey(type))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        internal static string SerializeBaseType(object thing, Type type, FileStyle style)
        {
            if (BaseSerializeMethods.TryGetValue(type, out var method))
            {
                return(method(thing));
            }

            if (BaseStyledSerializeMethods.TryGetValue(type, out var stylemethod))
            {
                return(stylemethod(thing, style));
            }

            if (type.IsEnum)
            {
                return(SerializeEnum(thing, style));
            }

            throw new Exception($"Cannot serialize base type {type} - are you sure it is a base type?");
        }