/// <inheritdoc /> public IThingProperty Create(Type propertyType, JsonSchema jsonSchema, Thing thing, Action <object, object?>?setter, Func <object, object?> getter, string originPropertyName) { propertyType = propertyType.GetUnderlyingType(); var code = propertyType.ToTypeCode(); var jsonConvertible = _jsonConvertibleFactory.Create(code, propertyType); var validation = _validationFactory.Create(code, jsonSchema, propertyType); switch (code) { case TypeCode.Boolean: case TypeCode.String: case TypeCode.Char: case TypeCode.DateTime: case TypeCode.DateTimeOffset: case TypeCode.Guid: case TypeCode.TimeSpan: case TypeCode.Enum: return(new ThingProperty(thing, jsonSchema.IsReadOnly.GetValueOrDefault(), jsonSchema.IsWriteOnly.GetValueOrDefault(), getter, setter, validation, jsonConvertible, null, originPropertyName)); case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Float: case TypeCode.Double: case TypeCode.Decimal: return(new ThingProperty(thing, jsonSchema.IsReadOnly.GetValueOrDefault(), jsonSchema.IsWriteOnly.GetValueOrDefault(), getter, setter, validation, jsonConvertible, _convertibleFactory.Create(code, propertyType), originPropertyName)); case TypeCode.Array: return(new ThingProperty(thing, jsonSchema.IsReadOnly.GetValueOrDefault(), jsonSchema.IsWriteOnly.GetValueOrDefault(), getter, setter, validation, jsonConvertible, _convertibleFactory.Create(code, propertyType), originPropertyName)); default: throw new ArgumentOutOfRangeException(); } }
/// <inheritdoc /> public IActionBuilder Add(ParameterInfo parameter, JsonSchema jsonSchema) { if (_input == null) { throw new InvalidOperationException($"ThingOption is null, call {nameof(Add)} before add"); } CreateProperty(_input, jsonSchema.Name, parameter.ParameterType); var parameterType = parameter.ParameterType.GetUnderlyingType(); var code = parameterType.ToTypeCode(); _jsonConvertibles !.Add(jsonSchema.Name, _jsonConvertibleFactory.Create(code, parameterType)); _jsonSchemaValidations !.Add(jsonSchema.Name, _jsonSchemaValidationFactory.Create(code, jsonSchema, parameterType)); _convertibles !.Add(jsonSchema.Name, _convertibleFactory.Create(code, parameterType)); return(this); }