Example #1
0
        public static Type ToTomlClassType(this TomlObjectType t)
        {
            switch (t)
            {
            case TomlObjectType.Bool: return(Types.TomlBoolType);

            case TomlObjectType.String: return(Types.TomlStringType);

            case TomlObjectType.Int: return(Types.TomlIntType);

            case TomlObjectType.Float: return(Types.TomlFloatType);

            case TomlObjectType.DateTime: return(Types.TomlDateTimeType);

            case TomlObjectType.LocalDate: return(Types.TomlLocalDate);

            case TomlObjectType.LocalDateTime: return(Types.TomlLocalDateTime);

            case TomlObjectType.LocalTime: return(Types.TomlLocalTime);

            case TomlObjectType.TimeSpan: return(Types.TomlTimeSpanType);

            case TomlObjectType.Array: return(Types.TomlArrayType);

            case TomlObjectType.Table: return(Types.TomlTableType);

            case TomlObjectType.ArrayOfTables: return(Types.TomlTableArrayType);

            default:
                throw new InvalidOperationException($"Cannot convert '{t}' to corresponding class type.");
            }
        }
Example #2
0
 public ValueSegment(TomlObjectType segmentType, string key)
     : base(segmentType, key)
 {
     if (segmentType > TomlObjectType.TimeSpan)
     {
         throw new ArgumentException(
             $"The passed TOML type '{segmentType}' is invalid because it is not a TOML value type.");
     }
 }
Example #3
0
            public KeySegment(TomlObjectType segmentType, string key)
                : base(segmentType)
            {
                if (string.IsNullOrWhiteSpace(key))
                {
                    throw new ArgumentException(nameof(key));
                }
                this.key = key;

                this.ThrowWhenKeyNotFound = _ => throw new InvalidOperationException(this.KeyNotFoundMessage);
            }
Example #4
0
            private static ITPathSegment GetSegmentFromTargetType(TomlObjectType targetType, Type clrType, string key)
            {
                switch (targetType)
                {
                case TomlObjectType.Table: return(new TableSegment(key, clrType));

                case TomlObjectType.ArrayOfTables: return(new TableArraySegment(key));

                case TomlObjectType.Array: return(new ArraySegment(key));

                default: return(new ValueSegment(targetType, key));
                }
            }
Example #5
0
        internal TomlArray(ITomlRoot root, params TomlValue[] values)
            : base(root, values)
        {
            if (values.Length > 1)
            {
                TomlObjectType primaryType = values[0].TomlType;

                for (int i = 1; i < values.Length; i++)
                {
                    if (values[i].TomlType != primaryType)
                    {
                        throw new ArgumentException($"All TOML array elements should have the same type as the first item. " +
                                                    $"First item has type '{values[0].ReadableTypeName}', but element at index '{i}' has type " +
                                                    $"'{values[i].ReadableTypeName}'.");
                    }
                }
            }
        }
Example #6
0
 public Segment(TomlObjectType segmentType)
 {
     this.segmentType = segmentType;
 }