Beispiel #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);
        }
Beispiel #2
0
        /// <summary> Non-generic version of ParseBaseType </summary>
        public static object ParseBaseType(string text, Type type)
        {
            try
            {
                if (BaseParseMethods.TryGetValue(type, out var method))
                {
                    return(method(text));
                }

                if (type.IsEnum)
                {
                    return(ParseEnum(text, type));
                }
            }
            catch { throw new Exception($"Error parsing text {text} as type {type}"); }

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