diff --git a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs index 2c5f3ebf0fced5..7980b383a49f87 100644 --- a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs +++ b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs @@ -33,7 +33,7 @@ private sealed class Parser private const string JsonPropertyNameAttributeFullName = "System.Text.Json.Serialization.JsonPropertyNameAttribute"; private const string JsonPropertyOrderAttributeFullName = "System.Text.Json.Serialization.JsonPropertyOrderAttribute"; private const string JsonSerializerContextFullName = "System.Text.Json.Serialization.JsonSerializerContext"; - private const string JsonSerializerAttributeFullName = "System.Text.Json.Serialization.JsonSerializableAttribute"; + private const string JsonSerializableAttributeFullName = "System.Text.Json.Serialization.JsonSerializableAttribute"; private const string JsonSourceGenerationOptionsAttributeFullName = "System.Text.Json.Serialization.JsonSourceGenerationOptionsAttribute"; private readonly Compilation _compilation; @@ -94,6 +94,14 @@ private sealed class Parser defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true); + private static DiagnosticDescriptor ContextClassesMustIndicateSerializableTypes { get; } = new DiagnosticDescriptor( + id: "SYSLIB1032", + title: new LocalizableResourceString(nameof(SR.ContextClassesMustIndicateSerializableTypesTitle), SR.ResourceManager, typeof(FxResources.System.Text.Json.SourceGeneration.SR)), + messageFormat: new LocalizableResourceString(nameof(SR.ContextClassesMustIndicateSerializableTypesMessageFormat), SR.ResourceManager, typeof(FxResources.System.Text.Json.SourceGeneration.SR)), + category: JsonConstants.SystemTextJsonSourceGenerationName, + defaultSeverity: DiagnosticSeverity.Warning, + isEnabledByDefault: true); + private static DiagnosticDescriptor MultipleJsonConstructorAttribute { get; } = new DiagnosticDescriptor( id: "SYSLIB1033", title: new LocalizableResourceString(nameof(SR.MultipleJsonConstructorAttributeTitle), SR.ResourceManager, typeof(FxResources.System.Text.Json.SourceGeneration.SR)), @@ -149,7 +157,7 @@ public Parser(Compilation compilation, in SourceProductionContext sourceProducti { Compilation compilation = _compilation; INamedTypeSymbol jsonSerializerContextSymbol = compilation.GetBestTypeByMetadataName(JsonSerializerContextFullName); - INamedTypeSymbol jsonSerializableAttributeSymbol = compilation.GetBestTypeByMetadataName(JsonSerializerAttributeFullName); + INamedTypeSymbol jsonSerializableAttributeSymbol = compilation.GetBestTypeByMetadataName(JsonSerializableAttributeFullName); INamedTypeSymbol jsonSourceGenerationOptionsAttributeSymbol = compilation.GetBestTypeByMetadataName(JsonSourceGenerationOptionsAttributeFullName); if (jsonSerializerContextSymbol == null || jsonSerializableAttributeSymbol == null || jsonSourceGenerationOptionsAttributeSymbol == null) @@ -193,19 +201,27 @@ public Parser(Compilation compilation, in SourceProductionContext sourceProducti } } + INamedTypeSymbol contextTypeSymbol = (INamedTypeSymbol)compilationSemanticModel.GetDeclaredSymbol(classDeclarationSyntax); + Debug.Assert(contextTypeSymbol != null); + string[] diagnosticMessageArgs = new string[] { contextTypeSymbol.Name }; + if (serializableAttributeList == null) { // No types were indicated with [JsonSerializable] + + // If there are no members on the context, assume that the user wanted source generation and notify them that there are no serializable types. + if (!contextTypeSymbol.MemberNames.Any()) + { + _sourceProductionContext.ReportDiagnostic(Diagnostic.Create(ContextClassesMustIndicateSerializableTypes, Location.None, diagnosticMessageArgs)); + } + continue; } - INamedTypeSymbol contextTypeSymbol = (INamedTypeSymbol)compilationSemanticModel.GetDeclaredSymbol(classDeclarationSyntax); - Debug.Assert(contextTypeSymbol != null); - if (!TryGetClassDeclarationList(contextTypeSymbol, out List classDeclarationList)) { // Class or one of its containing types is not partial so we can't add to it. - _sourceProductionContext.ReportDiagnostic(Diagnostic.Create(ContextClassesMustBePartial, Location.None, new string[] { contextTypeSymbol.Name })); + _sourceProductionContext.ReportDiagnostic(Diagnostic.Create(ContextClassesMustBePartial, Location.None, diagnosticMessageArgs)); continue; } @@ -407,31 +423,25 @@ private static bool TryGetClassDeclarationList(INamedTypeSymbol typeSymbol, [Not return typeGenerationSpec; } - internal static bool IsSyntaxTargetForGeneration(SyntaxNode node) => node is ClassDeclarationSyntax { AttributeLists: { Count: > 0 }, BaseList: { Types : {Count : > 0 } } }; + internal static bool IsSyntaxTargetForGeneration(SyntaxNode node) => node is ClassDeclarationSyntax { BaseList: { Types : { Count : > 0 } } }; internal static ClassDeclarationSyntax? GetSemanticTargetForGeneration(GeneratorSyntaxContext context) { var classDeclarationSyntax = (ClassDeclarationSyntax)context.Node; - foreach (AttributeListSyntax attributeListSyntax in classDeclarationSyntax.AttributeLists) + foreach (BaseTypeSyntax baseTypeSyntax in classDeclarationSyntax.BaseList.Types) { - foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes) + INamedTypeSymbol? baseTypeSymbol = context.SemanticModel.GetSymbolInfo(baseTypeSyntax.Type).Symbol as INamedTypeSymbol; + if (baseTypeSymbol == null) { - IMethodSymbol attributeSymbol = context.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol as IMethodSymbol; - if (attributeSymbol == null) - { - continue; - } - - INamedTypeSymbol attributeContainingTypeSymbol = attributeSymbol.ContainingType; - string fullName = attributeContainingTypeSymbol.ToDisplayString(); - - if (fullName == "System.Text.Json.Serialization.JsonSerializableAttribute") - { - return classDeclarationSyntax; - } + continue; } + string fullName = baseTypeSymbol.ToDisplayString(); + if (fullName == JsonSerializerContextFullName) + { + return classDeclarationSyntax; + } } return null; diff --git a/src/libraries/System.Text.Json/gen/Resources/Strings.resx b/src/libraries/System.Text.Json/gen/Resources/Strings.resx index 5e60f5e377c5d6..33d5790db02760 100644 --- a/src/libraries/System.Text.Json/gen/Resources/Strings.resx +++ b/src/libraries/System.Text.Json/gen/Resources/Strings.resx @@ -130,7 +130,7 @@ Did not generate serialization metadata for type. - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. Derived 'JsonSerializerContext' types and all containing types must be partial. @@ -141,4 +141,10 @@ Type has multiple constructors annotated with JsonConstructorAttribute. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + \ No newline at end of file diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf index 4bde155b650b24..98a2f305b58648 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - Odvozený typ JsonSerializerContext {0} určuje typy serializovatelné na JSON. Typ a všechny obsahující typy musí být částečné, aby se zahájilo generování zdroje. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + Odvozený typ JsonSerializerContext {0} určuje typy serializovatelné na JSON. Typ a všechny obsahující typy musí být částečné, aby se zahájilo generování zdroje. @@ -12,6 +12,16 @@ Odvozené typy JsonSerializerContext a všechny obsahující typy musí být částečné. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Existuje několik typů s názvem {0}. Zdroj se vygeneroval pro první zjištěný typ. Tuto kolizi vyřešíte pomocí JsonSerializableAttribute.TypeInfoPropertyName. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf index 093d8a6cdb4715..f82d0b66d3d86f 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - Der abgeleitete JsonSerializerContext-Typ "{0}" gibt serialisierbare JSON-Typen an. Der Typ und alle enthaltenden Typen müssen partiell sein, um die Quellgenerierung zu starten. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + Der abgeleitete JsonSerializerContext-Typ "{0}" gibt serialisierbare JSON-Typen an. Der Typ und alle enthaltenden Typen müssen partiell sein, um die Quellgenerierung zu starten. @@ -12,6 +12,16 @@ Abgeleitete JsonSerializerContext-Typen und alle enthaltenden Typen müssen partiell sein. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Es sind mehrere Typen namens "{0}" vorhanden. Die Quelle wurde für den ersten festgestellten Typ generiert. Verwenden Sie "JsonSerializableAttribute.TypeInfoPropertyName", um diesen Konflikt zu beheben. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf index ed12d993f5c5a6..94466b21650074 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - El tipo derivado "JsonSerializerContext" "{0}" especifica tipos de JSON serializables. El tipo y todos los tipos que contienen deben hacerse parciales para iniciar la generación de origen. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + El tipo derivado "JsonSerializerContext" "{0}" especifica tipos de JSON serializables. El tipo y todos los tipos que contienen deben hacerse parciales para iniciar la generación de origen. @@ -12,6 +12,16 @@ Los tipos derivados "JsonSerializerContext" y todos los tipos que contienen deben ser parciales. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Hay varios tipos denominados {0}. El origen se generó para el primero detectado. Use "JsonSerializableAttribute.TypeInfoPropertyName" para resolver esta colisión. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf index ddea910bd05ba9..a117fc6f941572 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - Le type 'JsonSerializerContext' dérivé '{0}' spécifie des types Sérialisables JSON. Le type et tous les types contenants doivent être rendus partiels pour lancer la génération de la source. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + Le type 'JsonSerializerContext' dérivé '{0}' spécifie des types Sérialisables JSON. Le type et tous les types contenants doivent être rendus partiels pour lancer la génération de la source. @@ -12,6 +12,16 @@ Les types dérivés 'JsonSerializerContext' et tous les types conteneurs doivent être partiels. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Plusieurs types nommés {0}. La source a été générée pour la première détection détectée. Utilisez « JsonSerializableAttribute.TypeInfoPropertyName » pour résoudre cette collision. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf index d26aba1c84f9b9..a0cf372148ea49 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - Il tipo 'JsonSerializerContext 'derivato '{0}' specifica i tipi serializzabili JSON. Il tipo e tutti i tipi contenenti devono essere parziali per iniziare la generazione dell'origine. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + Il tipo 'JsonSerializerContext 'derivato '{0}' specifica i tipi serializzabili JSON. Il tipo e tutti i tipi contenenti devono essere parziali per iniziare la generazione dell'origine. @@ -12,6 +12,16 @@ I tipi derivati 'JsonSerializerContext' e tutti i tipi contenenti devono essere parziali. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Sono presenti più tipi denominati {0}. L'origine è stata generata per il primo tipo rilevato. Per risolvere questa collisione, usare 'JsonSerializableAttribute.TypeInfoPropertyName'. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf index 50270d6c4d401d..cb9b4fa09e33eb 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - 派生した 'JsonSerializerContext'型 '{0}' は、JSON シリアル化可能な型を指定します。ソース生成を開始するには、型と含まれているすべての型を部分的にする必要があります。 + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + 派生した 'JsonSerializerContext'型 '{0}' は、JSON シリアル化可能な型を指定します。ソース生成を開始するには、型と含まれているすべての型を部分的にする必要があります。 @@ -12,6 +12,16 @@ 派生した 'JsonSerializerContext' 型と含まれているすべての型は部分的である必要があります。 + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. {0} と名前が付けられた種類が複数あります。最初に検出されたものに対してソースが生成されました。この問題を解決するには、'JsonSerializableAttribute.TypeInfoPropertyName' を使用します。 diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf index a1fd856af18575..5c8f820e966688 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - 파생된 'JsonSerializerContext' 유형 '{0}'은(는) JSON 직렬화 가능한 유형을 지정합니다. 소스 생성을 위해 유형 및 모든 포함 유형을 부분적으로 만들어야 합니다. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + 파생된 'JsonSerializerContext' 유형 '{0}'은(는) JSON 직렬화 가능한 유형을 지정합니다. 소스 생성을 위해 유형 및 모든 포함 유형을 부분적으로 만들어야 합니다. @@ -12,6 +12,16 @@ 파생된 'JsonSerializerContext' 형식과 포함하는 모든 형식은 부분이어야 합니다. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. 이름이 {0}인 형식이 여러 개 있습니다. 처음 검색한 원본에 대해 원본이 생성되었습니다. 이 충돌을 해결하려면 'JsonSerializableAttribute.TypeInfoPropertyName'을 사용하세요. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf index e04db80de054be..d74509857b0d77 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - Pochodny typ "JsonSerializerContext" "{0}" określa typy możliwe do serializacji w notacji JSON. Typ i wszystkie zawierające typy muszą być częściowe, aby uruchomić generowanie źródła. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + Pochodny typ "JsonSerializerContext" "{0}" określa typy możliwe do serializacji w notacji JSON. Typ i wszystkie zawierające typy muszą być częściowe, aby uruchomić generowanie źródła. @@ -12,6 +12,16 @@ Pochodne typy "JsonSerializerContext" i wszystkich zawierające typy muszą być częściowe. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Istnieje wiele typów o nazwie {0}. Wygenerowano źródło dla pierwszego wykrytego elementu. Aby rozwiązać tę kolizję, użyj „JsonSerializableAttribute. TypeInfoPropertyName”. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf index bd08c889d012fd..964eb6a64ef9e9 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - O tipo 'JsonSerializerContext' derivado '{0}' especifica tipos serializáveis por JSON. O tipo e todos os tipos de contenção devem ser feitos parcialmente para iniciar a geração de origem. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + O tipo 'JsonSerializerContext' derivado '{0}' especifica tipos serializáveis por JSON. O tipo e todos os tipos de contenção devem ser feitos parcialmente para iniciar a geração de origem. @@ -12,6 +12,16 @@ Os tipos derivados de 'JsonSerializerContext' e todos os tipos contidos devem ser parciais. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Existem vários tipos chamados {0}. A fonte foi gerada para o primeiro detectado. Use 'JsonSerializableAttribute.TypeInfoPropertyName' para resolver esta colisão. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf index fdd7824a1f54eb..b573af73260165 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - Производный тип "JsonSerializerContext"{0}' указывает сериализуемые типы в формате JSON. Тип и все содержащие типы необходимо сделать частичными для начала генерации источника. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + Производный тип "JsonSerializerContext"{0}' указывает сериализуемые типы в формате JSON. Тип и все содержащие типы необходимо сделать частичными для начала генерации источника. @@ -12,6 +12,16 @@ Производные типы "JsonSerializerContext" и все содержащие типы должны быть частичными. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Существует несколько типов с именем {0}. Исходный код сформирован для первого обнаруженного типа. Используйте JsonSerializableAttribute.TypeInfoPropertyName для устранения этого конфликта. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf index 7844892dcbb498..5530f4cba8fa83 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - Türetilmiş 'JsonSerializerContext' türü '{0}' JSON ile seri hale getirilebilir türleri belirtir. kaynak oluşturmayı başlatmak için bu türün ve bu türü içeren tüm türlerin kısmi yapılması gerekir. + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + Türetilmiş 'JsonSerializerContext' türü '{0}' JSON ile seri hale getirilebilir türleri belirtir. kaynak oluşturmayı başlatmak için bu türün ve bu türü içeren tüm türlerin kısmi yapılması gerekir. @@ -12,6 +12,16 @@ Türetilmiş 'JsonSerializerContext' türleri ve bunları içeren tüm türler kısmi olmalıdır. + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. {0} adını taşıyan birden çok tür var. Kaynak, algılanan ilk tür için oluşturuldu. Bu çarpışmayı çözmek için 'JsonSerializableAttribute.TypeInfoPropertyName' özelliğini kullanın. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf index 10e68c87ede68d..59b8f5e9f3f96e 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - 派生的 “JsonSerializerContext” 类型“{0}”指定 JSON-serializable 类型。该类型和所有包含类型必须设为部分,以启动源生成。 + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + 派生的 “JsonSerializerContext” 类型“{0}”指定 JSON-serializable 类型。该类型和所有包含类型必须设为部分,以启动源生成。 @@ -12,6 +12,16 @@ 派生的 “JsonSerializerContext” 类型以及所有包含类型必须是部分。 + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. 有多个名为 {0} 的类型。已为第一个检测到类型的生成源。请使用 'JsonSerializableAttribute.TypeInfoPropertyName' 以解决此冲突。 diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf index 2b5a59991a12a7..f4fc925f06f743 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf @@ -3,8 +3,8 @@ - Derived 'JsonSerializerContext' type '{0}' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation. - 衍生的 'JsonSerializerContext' 型別 '{0}' 指定了 JSON 可序列化類型。類型和所有包含類型必須設為部份,才可開始產生原始檔。 + Derived 'JsonSerializerContext' type '{0}' and all containing types must be made partial to kick off source generation. + 衍生的 'JsonSerializerContext' 型別 '{0}' 指定了 JSON 可序列化類型。類型和所有包含類型必須設為部份,才可開始產生原始檔。 @@ -12,6 +12,16 @@ 衍生的 'JsonSerializerContext' 類型和所有包含類型必須是部份。 + + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + Derived 'JsonSerializerContext' type '{0}' must indicate at least one serializable type using 'JsonSerializableAttribute'. + + + + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + Derived 'JsonSerializerContext' type '{0}' must indicate serializable types. + + There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. 有多個名為 {0} 的類型。已為偵測到的第一個項目產生來源。請使用 'JsonSerializableAttribute.TypeInfoPropertyName' 解決此衝突。 diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs index caa283f25f91a3..8b558916ea9b3a 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Xunit; @@ -190,5 +191,46 @@ public static void Main() CompilationHelper.CheckDiagnosticMessages(generatorDiags, DiagnosticSeverity.Warning, Array.Empty()); CompilationHelper.CheckDiagnosticMessages(generatorDiags, DiagnosticSeverity.Error, Array.Empty()); } + + [Fact] + public void ContextTypeNoSerializableTypes_EmptyContext() + { + string source = @" + using System.Text.Json.Serialization; + + internal partial class JsonContext : JsonSerializerContext + { + }"; + + Compilation compilation = CompilationHelper.CreateCompilation(source); + JsonSourceGenerator generator = new JsonSourceGenerator(); + + CompilationHelper.RunGenerators(compilation, out ImmutableArray generatorDiags, generator); + + string[] expectedWarningDiagnostics = new string[] { "Derived 'JsonSerializerContext' type 'JsonContext' must indicate at least one serializable type using 'JsonSerializableAttribute'." }; + CompilationHelper.CheckDiagnosticMessages(generatorDiags, DiagnosticSeverity.Warning, expectedWarningDiagnostics); + } + + [Fact] + public void ContextTypeNoSerializableTypes_ContextWithMembers() + { + string source = @" + using System.Text.Json.Serialization; + + internal partial class JsonContext : JsonSerializerContext + { + } + + internal partial class JsonContext : JsonSerializerContext + { + private bool _dummy; + }"; + + Compilation compilation = CompilationHelper.CreateCompilation(source); + JsonSourceGenerator generator = new JsonSourceGenerator(); + + CompilationHelper.RunGenerators(compilation, out ImmutableArray generatorDiags, generator); + CompilationHelper.CheckDiagnosticMessages(generatorDiags, DiagnosticSeverity.Warning, Array.Empty()); + } } }