diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs index b0dbeea67f5b78..f5ed61fb817e5d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs @@ -4,13 +4,9 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.DotnetRuntime.Extensions; @@ -395,6 +391,17 @@ public static ImmutableDictionary CreateDiagnosticPropertiesForM isEnabledByDefault: true, description: GetResourceString(nameof(SR.ManagedTypeMustBeNonNullDescription))); + /// + public static readonly DiagnosticDescriptor MarshalModeMustBeValidValue = + new DiagnosticDescriptor( + Ids.InvalidCustomMarshallerAttributeUsage, + GetResourceString(nameof(SR.InvalidMarshalModeTitle)), + GetResourceString(nameof(SR.MarshalModeMustBeValidEnumValue)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.MarshalModeMustBeValidEnumValue))); + // We are intentionally using the same diagnostic IDs as the parent type. // These diagnostics are the same diagnostics, but with a different severity, // as the Default marshaller shape can have support for the managed-to-unmanaged shape @@ -676,11 +683,19 @@ public void AnalyzeAttribute(OperationAnalysisContext context) { return; } + var marshalModeArgument = attrCreation.GetArgumentByOrdinal(1); + if (marshalModeArgument.Value is not IFieldReferenceOperation { ConstantValue.Value: var marshalMode } + || !Enum.IsDefined(typeof(MarshalMode), (MarshalMode)marshalMode)) + { + DiagnosticReporter marshalModeReporter = DiagnosticReporter.CreateForLocation(marshalModeArgument.Syntax.GetLocation(), context.ReportDiagnostic); + marshalModeReporter.CreateAndReportDiagnostic(MarshalModeMustBeValidValue); + return; + } AnalyzeMarshallerType( marshallerTypeReporter, managedType, - (MarshalMode)attrCreation.GetArgumentByOrdinal(1).Value.ConstantValue.Value, + (MarshalMode)marshalMode, (INamedTypeSymbol)marshallerType, ManualTypeMarshallingHelper.IsLinearCollectionEntryPoint(entryType)); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx index 8224ad74f4b73f..d05dd577c8b606 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx @@ -1,17 +1,17 @@  - @@ -497,4 +497,10 @@ Convert to 'LibraryImport' with '{0}' suffix and enable unsafe code + + Invalid 'MarshalMode' value. + + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf index 0371a69dfb1063..b5212d6d007901 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf @@ -217,6 +217,11 @@ Zadaný spravovaný typ je neplatný + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid Zadaný zařazovací typ je neplatný @@ -312,6 +317,11 @@ Spravovaný typ pro zařazovací typ vstupního bodu {0} nesmí nabývat hodnoty null. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. Zařazovací typ musí být uzavřený obecný typ nebo mít stejný počet obecných parametrů jako spravovaný typ, aby mohl vygenerovaný kód použít konkrétní vytvoření instance. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf index 6568eef9a5179e..b4f25336b85c82 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf @@ -217,6 +217,11 @@ Der angegebene verwaltete Typ ist ungültig. + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid Der angegebene Marshallertyp ist ungültig. @@ -312,6 +317,11 @@ Der verwaltete Typ für den Einstiegspunkt-Marshallertyp "{0}" darf nicht "NULL" sein + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. Der Marshaller-Typ muss ein geschlossener generischer Typ sein oder dieselbe Anzahl generischer Parameter wie der verwaltete Typ aufweisen, damit der ausgegebene Code eine bestimmte Instanziierung verwenden kann. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf index 466e28d4ce7b75..5cbbc2ee9a1306 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf @@ -217,6 +217,11 @@ El tipo administrado especificado no es válido + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid El tipo de serializador especificado no es válido @@ -312,6 +317,11 @@ El tipo administrado para el tipo de serializador de punto de entrada "{0}" no debe ser "null" + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. El tipo serializador debe ser un genérico cerrado o tener el mismo número de parámetros genéricos que el tipo administrado para que el código emitido pueda usar una creación de instancia específica. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf index 085613c575fb5c..1809d7ac02029d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf @@ -217,6 +217,11 @@ Le type managé spécifié n’est pas valide + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid Le type de marshaleur spécifié n’est pas valide @@ -312,6 +317,11 @@ Le type managé du type marshaleur de point d’entrée « {0} » ne doit pas avoir la valeur 'null' + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. Le type marshaler doit être un générique fermé ou avoir le même nombre de paramètres génériques que le type managé pour que le code émis puisse utiliser une instanciation spécifique. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf index 30039cecd7c00c..22f9e58491ca38 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf @@ -217,6 +217,11 @@ Il tipo gestito specificato non è valido + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid Il tipo di marshaller specificato non è valido @@ -312,6 +317,11 @@ Il tipo gestito per il tipo di marshaller del punto di ingresso '{0}' non deve essere 'null' + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. Il tipo di marshaller deve essere un generico chiuso o avere lo stesso numero di parametri generici del tipo gestito, in modo che il codice generato possa usare una creazione di istanza specifica. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf index ecf2587cbdf319..9ee8299f0ea570 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf @@ -217,6 +217,11 @@ 指定されたマネージド型が無効です + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid 指定されたマーシャラー型が無効です @@ -312,6 +317,11 @@ エントリ ポイント マーシャラー型 '{0}' のマネージド型を 'null' にすることはできません + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. マーシャラー型は、クローズ ジェネリックであるか、マネージド型と同じ数のジェネリック パラメーターを持つ必要があります。これにより、生成されたコードが特定のインスタンス化を使用できるようになります。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf index 472d83e9e2eb21..cc4bc77517d36d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf @@ -217,6 +217,11 @@ 지정된 관리 유형이 잘못되었습니다. + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid 지정된 마샬러 유형이 잘못되었습니다. @@ -312,6 +317,11 @@ 진입점 마샬러 유형 '{0}'의 관리 유형은 'null'이 아니어야 합니다. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. 마샬러 형식은 닫힌 제네릭이거나 관리되는 형식과 동일한 수의 제네릭 매개 변수가 있어야 내보낸 코드에서 특정 인스턴스화를 사용할 수 있습니다. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf index c676a94b3cf76f..d0b5e5ed20fed8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf @@ -217,6 +217,11 @@ Określony typ zarządzany jest nieprawidłowy + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid Określony typ marshallera jest nieprawidłowy @@ -312,6 +317,11 @@ Typ zarządzany dla typu marshaller punktu wejścia „{0}” nie może mieć wartości „null” + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. Typ marshallera musi być zamkniętym typem ogólnym lub mieć taką samą liczbę parametrów ogólnych jak typ zarządzany, aby emitowany kod mógł używać określonego wystąpienia. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf index 0287f442c221ea..ebd39b8487dfbd 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf @@ -217,6 +217,11 @@ O tipo gerenciado especificado é inválido + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid O tipo de empacotador especificado é inválido @@ -312,6 +317,11 @@ O tipo gerenciado para o tipo de empacotador de ponto de entrada '{0}' não deve ser 'nulo' + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. O tipo de empacotador deve ser um genérico fechado ou ter o mesmo número de parâmetros genéricos que o tipo gerenciado para que o código emitido possa usar uma instanciação específica. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf index 2a5d553958d215..755e0c157a34f2 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf @@ -217,6 +217,11 @@ Указан недопустимый управляемый тип + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid Указан недопустимый тип маршалера @@ -312,6 +317,11 @@ Управляемый тип для типа маршалера точки входа "{0}" должен отличаться от "NULL" + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. Тип маршалера должен быть закрытым универсальным или иметь то же количество универсальных параметров, что и управляемый тип, чтобы создаваемый код мог использовать конкретный экземпляр. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf index 7734ac571418d5..39173fb5d0cdd1 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf @@ -217,6 +217,11 @@ Belirtilen yönetilen tür geçersiz + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid Belirtilen hazırlayıcı türü geçersiz @@ -312,6 +317,11 @@ Giriş noktası hazırlayıcı türü '{0}' için yönetilen tür 'null' olmamalıdır + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. Hazırlayıcı türü kapalı bir genel tür olmalıdır veya gösterilen kodun belirli bir örnek oluşturma kullanabilmesi için yönetilen türle aynı sayıda genel parametreye sahip olmalıdır. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf index 1a804b14381b3b..6ed83988fdb531 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf @@ -217,6 +217,11 @@ 指定的托管类型无效 + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid 指定的封送处理程序类型无效 @@ -312,6 +317,11 @@ 入口点封送处理程序类型“{0}”的托管类型不能为“null” + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. 封送处理程序类型必须是封闭泛型或具有与托管类型相同数目的泛型参数,以便发出的代码可以使用特定实例化。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf index 0673dd5cf0f962..b8a7111c3a0bff 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf @@ -217,6 +217,11 @@ 指定的受控類型無效 + + Invalid 'MarshalMode' value. + Invalid 'MarshalMode' value. + + Specified marshaller type is invalid 指定的封送處理器類型無效 @@ -312,6 +317,11 @@ 進入點封送處理器類型 '{0}' 的受控類型不得為 'null' + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. + + The marshaller type must be a closed generic or have the same number of generic parameters as the managed type so the emitted code can use a specific instantiation. 封送處理器類型必須是封閉式泛型或具有與受控類型相同的泛型參數數目,因此發出的程式碼可以使用特定的具現化。 diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_AttributeUsage.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_AttributeUsage.cs index 03775e7aef3a18..dd47fcba5fac0a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_AttributeUsage.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_AttributeUsage.cs @@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Testing; using System.Collections.Generic; +using System.Runtime.InteropServices.Marshalling; using System.Threading.Tasks; using Xunit; using static Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer; @@ -30,6 +31,41 @@ static class MarshallerType {} await VerifyCS.VerifyAnalyzerAsync(source, VerifyCS.Diagnostic(ManagedTypeMustBeNonNullRule).WithLocation(0).WithArguments("MarshallerType")); } + [Fact] + public async Task UsingMarshalModeAsFlags_ReportsDiagnostic() + { + string source = """ + using System.Collections.Generic; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + [CustomMarshaller(typeof(int), {|#0:MarshalMode.ElementIn | MarshalMode.ElementOut | MarshalMode.Default|}, typeof(MyMarshaller))] + public static class MyMarshaller + { + + } + """; + + await VerifyCS.VerifyAnalyzerAsync(source, + VerifyCS.Diagnostic(MarshalModeMustBeValidValue).WithLocation(0)); + } + + [Fact] + public async Task UsingInvalidMarshalMode_ReportsDiagnostic() + { + string source = """ + using System.Collections.Generic; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + [CustomMarshaller(typeof(int), {|#0:(MarshalMode)10|}, typeof(MyMarshaller))] + public static class MyMarshaller + { + + } + """; + + await VerifyCS.VerifyAnalyzerAsync(source, + VerifyCS.Diagnostic(MarshalModeMustBeValidValue).WithLocation(0)); + } [Fact] public async Task MarshallerWithEntryPointAttributeForType_DoesNotReportDiagnostic()