@@ -324,7 +324,7 @@ private string GenerateForTypeWithUnknownConverter(TypeGenerationSpec typeMetada
324
324
}}
325
325
else
326
326
{{
327
- throw new { InvalidOperationExceptionTypeRef } ($""The converter '{{converter .GetType()}}' is not compatible with the type '{{ typeToConvert}}'."" );
327
+ throw new { InvalidOperationExceptionTypeRef } (string.Format("" { SR . Exception_IncompatibleConverterType } "", converter.GetType(), typeToConvert) );
328
328
}}
329
329
}}" ) ;
330
330
}
@@ -333,7 +333,7 @@ private string GenerateForTypeWithUnknownConverter(TypeGenerationSpec typeMetada
333
333
metadataInitSource . Append ( $@ "
334
334
if (!converter.CanConvert(typeToConvert))
335
335
{{
336
- throw new { InvalidOperationExceptionTypeRef } ($""The converter '{{converter .GetType()}}' is not compatible with the type '{{ typeToConvert}}'."" );
336
+ throw new { InvalidOperationExceptionTypeRef } (string.Format("" { SR . Exception_IncompatibleConverterType } "", converter.GetType(), typeToConvert) );
337
337
}}" ) ;
338
338
}
339
339
@@ -711,25 +711,28 @@ private string GeneratePropMetadataInitFunc(TypeGenerationSpec typeGenerationSpe
711
711
? @$ "jsonPropertyName: ""{ memberMetadata . JsonPropertyName } """
712
712
: " jsonPropertyName: null ";
713
713
714
- string getterNamedArg = memberMetadata . CanUseGetter &&
715
- memberMetadata . DefaultIgnoreCondition != JsonIgnoreCondition . Always
716
- ? $ "getter: static (obj) => (({ declaringTypeCompilableName } )obj).{ clrPropertyName } "
717
- : "getter: null" ;
718
-
719
- string setterNamedArg ;
720
- if ( memberMetadata . CanUseSetter &&
721
- memberMetadata . DefaultIgnoreCondition != JsonIgnoreCondition . Always )
714
+ string getterNamedArg = memberMetadata switch
722
715
{
723
- string propMutation = typeGenerationSpec . IsValueType
724
- ? @$ "{ UnsafeTypeRef } .Unbox<{ declaringTypeCompilableName } >(obj).{ clrPropertyName } = value!"
725
- : $@ "(({ declaringTypeCompilableName } )obj).{ clrPropertyName } = value!";
726
-
727
- setterNamedArg = $ "setter: static (obj, value) => { propMutation } ";
728
- }
729
- else
716
+ { DefaultIgnoreCondition : JsonIgnoreCondition . Always } => "getter: null" ,
717
+ { CanUseGetter : true } => $ "getter: static (obj) => (({ declaringTypeCompilableName } )obj).{ clrPropertyName } ",
718
+ { CanUseGetter : false , HasJsonInclude : true }
719
+ => @$ "getter: static (obj) => throw new { InvalidOperationExceptionTypeRef } (""{ SR . Format ( SR . Exception_InaccessibleJsonIncludePropertiesNotSupported , typeGenerationSpec . Type . Name , memberMetadata . ClrName ) } "")",
720
+ _ => "getter: null"
721
+ } ;
722
+
723
+ string setterNamedArg = memberMetadata switch
730
724
{
731
- setterNamedArg = "setter: null" ;
732
- }
725
+ { DefaultIgnoreCondition : JsonIgnoreCondition . Always } => "setter: null" ,
726
+ { CanUseSetter : true , IsInitOnlySetter : true }
727
+ => @$ "setter: static (obj, value) => throw new { InvalidOperationExceptionTypeRef } (""{ SR . Exception_InitOnlyPropertyDeserializationNotSupported } "")",
728
+ { CanUseSetter : true } when typeGenerationSpec . IsValueType
729
+ => $@ "setter: static (obj, value) => { UnsafeTypeRef } .Unbox<{ declaringTypeCompilableName } >(obj).{ clrPropertyName } = value!",
730
+ { CanUseSetter : true }
731
+ => @$ "setter: static (obj, value) => (({ declaringTypeCompilableName } )obj).{ clrPropertyName } = value!",
732
+ { CanUseSetter : false , HasJsonInclude : true }
733
+ => @$ "setter: static (obj, value) => throw new { InvalidOperationExceptionTypeRef } (""{ SR . Format ( SR . Exception_InaccessibleJsonIncludePropertiesNotSupported , typeGenerationSpec . Type . Name , memberMetadata . ClrName ) } "")",
734
+ _ => "setter: null" ,
735
+ } ;
733
736
734
737
JsonIgnoreCondition ? ignoreCondition = memberMetadata . DefaultIgnoreCondition ;
735
738
string ignoreConditionNamedArg = ignoreCondition . HasValue
@@ -821,12 +824,12 @@ private string GenerateFastPathFuncForObject(TypeGenerationSpec typeGenSpec)
821
824
out Dictionary < string , PropertyGenerationSpec > ? serializableProperties ,
822
825
out bool castingRequiredForProps ) )
823
826
{
824
- string exceptionMessage = @$ """Invalid serializable-property configuration specified for type ' { typeRef } '. For more information, see 'JsonSourceGenerationMode.Serialization'.""" ;
827
+ string exceptionMessage = SR . Format ( SR . Exception_InvalidSerializablePropertyConfiguration , typeRef ) ;
825
828
826
829
return GenerateFastPathFuncForType (
827
830
serializeMethodName ,
828
831
typeRef ,
829
- $@ "throw new { InvalidOperationExceptionTypeRef } ({ exceptionMessage } );",
832
+ $@ "throw new { InvalidOperationExceptionTypeRef } ("" { exceptionMessage } "" );",
830
833
canBeNull : false ) ; // Skip null check since we want to throw an exception straightaway.
831
834
}
832
835
@@ -1202,7 +1205,7 @@ private string GetFetchLogicForRuntimeSpecifiedCustomConverter()
1202
1205
converter = factory.CreateConverter(type, { OptionsInstanceVariableName } );
1203
1206
if (converter == null || converter is { JsonConverterFactoryTypeRef } )
1204
1207
{{
1205
- throw new { InvalidOperationExceptionTypeRef } ($""The converter '{{ factory.GetType()}}' cannot return null or a JsonConverterFactory instance."" );
1208
+ throw new { InvalidOperationExceptionTypeRef } (string.Format("" { SR . Exception_InvalidJsonConverterFactoryOutput } "", factory.GetType()) );
1206
1209
}}
1207
1210
}}
1208
1211
@@ -1233,7 +1236,7 @@ private string GetFetchLogicForGetCustomConverter_TypesWithFactories()
1233
1236
{ JsonConverterTypeRef } ? converter = factory.CreateConverter(type, { Emitter . OptionsInstanceVariableName } );
1234
1237
if (converter == null || converter is { JsonConverterFactoryTypeRef } )
1235
1238
{{
1236
- throw new { InvalidOperationExceptionTypeRef } ($""The converter '{{ factory.GetType()}}' cannot return null or a JsonConverterFactory instance."" );
1239
+ throw new { InvalidOperationExceptionTypeRef } (string.Format("" { SR . Exception_InvalidJsonConverterFactoryOutput } "", factory.GetType()) );
1237
1240
}}
1238
1241
1239
1242
return converter;
0 commit comments