Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetConverterFromAttribute()

JsonConverter System.Text.Json.JsonSerializerOptions.GetConverterFromAttribute ( JsonConverterAttribute converterAttribute,
Type typeToConvert,
Type classTypeAttributeIsOn,
MemberInfo memberInfo )
inlineprivate

Definition at line 508 of file JsonSerializerOptions.cs.

509 {
510 Type converterType = converterAttribute.ConverterType;
512 if (converterType == null)
513 {
515 if (jsonConverter == null)
516 {
517 ThrowHelper.ThrowInvalidOperationException_SerializationConverterOnAttributeNotCompatible(classTypeAttributeIsOn, memberInfo, typeToConvert);
518 }
519 }
520 else
521 {
522 ConstructorInfo constructor = converterType.GetConstructor(Type.EmptyTypes);
523 if (!typeof(JsonConverter).IsAssignableFrom(converterType) || constructor == null || !constructor.IsPublic)
524 {
525 ThrowHelper.ThrowInvalidOperationException_SerializationConverterOnAttributeInvalid(classTypeAttributeIsOn, memberInfo);
526 }
527 jsonConverter = (JsonConverter)Activator.CreateInstance(converterType);
528 }
529 if (!jsonConverter.CanConvert(typeToConvert))
530 {
531 Type underlyingType = Nullable.GetUnderlyingType(typeToConvert);
532 if (underlyingType != null && jsonConverter.CanConvert(underlyingType))
533 {
535 {
536 jsonConverter = jsonConverterFactory.GetConverterInternal(underlyingType, this);
537 }
539 }
540 ThrowHelper.ThrowInvalidOperationException_SerializationConverterOnAttributeNotCompatible(classTypeAttributeIsOn, memberInfo, typeToConvert);
541 }
542 return jsonConverter;
543 }
static JsonConverter CreateValueConverter(Type valueTypeToConvert, JsonConverter valueConverter)

References System.Activator.CreateInstance(), System.Text.Json.Serialization.Converters.NullableConverterFactory.CreateValueConverter(), System.Text.Json.Dictionary, System.Type.EmptyTypes, System.Nullable< T >.GetUnderlyingType(), System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializationConverterOnAttributeInvalid(), and System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializationConverterOnAttributeNotCompatible().

Referenced by System.Text.Json.JsonSerializerOptions.DetermineConverter(), and System.Text.Json.JsonSerializerOptions.GetConverterInternal().