From a01aea999d340053ca6c351b0ad298706d097d9d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 29 Jul 2022 14:21:34 -0700 Subject: [PATCH] Add stateful marshaller support to the CustomMarshallerAttributeAnalyzer (#72888) --- .../Common/src/Interop/Interop.Ldap.cs | 2 + .../src/System/Drawing/Graphics.cs | 2 + .../CustomMarshallerAttributeAnalyzer.cs | 420 +++++++++++++++- .../Resources/Strings.resx | 48 +- .../Resources/xlf/Strings.cs.xlf | 72 ++- .../Resources/xlf/Strings.de.xlf | 72 ++- .../Resources/xlf/Strings.es.xlf | 72 ++- .../Resources/xlf/Strings.fr.xlf | 72 ++- .../Resources/xlf/Strings.it.xlf | 72 ++- .../Resources/xlf/Strings.ja.xlf | 72 ++- .../Resources/xlf/Strings.ko.xlf | 72 ++- .../Resources/xlf/Strings.pl.xlf | 72 ++- .../Resources/xlf/Strings.pt-BR.xlf | 72 ++- .../Resources/xlf/Strings.ru.xlf | 72 ++- .../Resources/xlf/Strings.tr.xlf | 72 ++- .../Resources/xlf/Strings.zh-Hans.xlf | 72 ++- .../Resources/xlf/Strings.zh-Hant.xlf | 72 ++- .../CollectionTests.cs | 1 + .../CustomMarshallingTests.cs | 2 + ...StatefulLinearCollectionShapeValidation.cs | 457 ++++++++++++++++++ ...FixerTests_StatefulValueShapeValidation.cs | 249 ++++++++++ ...tatelessLinearCollectionShapeValidation.cs | 2 +- ...ixerTests_StatelessValueShapeValidation.cs | 16 +- 23 files changed, 2024 insertions(+), 111 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulLinearCollectionShapeValidation.cs create mode 100644 src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulValueShapeValidation.cs diff --git a/src/libraries/Common/src/Interop/Interop.Ldap.cs b/src/libraries/Common/src/Interop/Interop.Ldap.cs index 7aac37cc97deb..478f5121c4996 100644 --- a/src/libraries/Common/src/Interop/Interop.Ldap.cs +++ b/src/libraries/Common/src/Interop/Interop.Ldap.cs @@ -263,6 +263,8 @@ public LdapReferralCallback ToManaged() } public void OnInvoked() => GC.KeepAlive(_managed); + + public void Free() {} } } #else diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs index b6f3fef8b1f5d..ca4040f1b9912 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs @@ -141,6 +141,8 @@ public void OnInvoked() { GC.KeepAlive(_managed); } + + public void Free() {} } } #endif 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 44de00121bc77..9603ec32cbc2c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs @@ -64,6 +64,17 @@ public static ImmutableDictionary CreateDiagnosticPropertiesForM isEnabledByDefault: true, description: GetResourceString(nameof(SR.MarshallerTypeMustBeStaticClassOrStructDescription))); + /// + public static readonly DiagnosticDescriptor ElementMarshallerCannotBeStatefulRule = + new DiagnosticDescriptor( + Ids.InvalidMarshallerType, + GetResourceString(nameof(SR.InvalidMarshallerTypeTitle)), + GetResourceString(nameof(SR.ElementMarshallerCannotBeStatefulMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.ElementMarshallerCannotBeStatefulDescription))); + /// public static readonly DiagnosticDescriptor UnmanagedTypeMustBeUnmanagedRule = new DiagnosticDescriptor( @@ -196,27 +207,93 @@ public static ImmutableDictionary CreateDiagnosticPropertiesForM isEnabledByDefault: true, description: GetResourceString(nameof(SR.StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsDescription))); - /// - public static readonly DiagnosticDescriptor CallerAllocConstructorMustHaveBufferSizeRule = + /// + public static readonly DiagnosticDescriptor CallerAllocFromManagedMustHaveBufferSizeRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.CallerAllocFromManagedMustHaveBufferSizeMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.CallerAllocFromManagedMustHaveBufferSizeDescription))); + + /// + public static readonly DiagnosticDescriptor StatelessLinearCollectionCallerAllocFromManagedMustHaveBufferSizeRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatelessLinearCollectionCallerAllocFromManagedMustHaveBufferSizeMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatelessLinearCollectionCallerAllocFromManagedMustHaveBufferSizeDescription))); + + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresFromManagedRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresFromManagedMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresFromManagedDescription))); + + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresToUnmanagedRule = new DiagnosticDescriptor( Ids.CustomMarshallerTypeMustHaveRequiredShape, GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), - GetResourceString(nameof(SR.CallerAllocConstructorMustHaveBufferSizeMessage)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresToUnmanagedMessage)), Category, DiagnosticSeverity.Error, isEnabledByDefault: true, - description: GetResourceString(nameof(SR.CallerAllocConstructorMustHaveBufferSizeDescription))); + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresToUnmanagedDescription))); - /// - public static readonly DiagnosticDescriptor StatelessLinearCollectionCallerAllocConstructorMustHaveBufferSizeRule = + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresToManagedRule = new DiagnosticDescriptor( Ids.CustomMarshallerTypeMustHaveRequiredShape, GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), - GetResourceString(nameof(SR.StatelessLinearCollectionCallerAllocConstructorMustHaveBufferSizeMessage)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresToManagedMessage)), Category, DiagnosticSeverity.Error, isEnabledByDefault: true, - description: GetResourceString(nameof(SR.StatelessLinearCollectionCallerAllocConstructorMustHaveBufferSizeDescription))); + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresToManagedDescription))); + + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresFromUnmanagedRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresFromUnmanagedMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresFromUnmanagedDescription))); + + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresFreeRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresFreeMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresFreeDescription))); + + /// + public static readonly DiagnosticDescriptor FromUnmanagedOverloadsNotSupportedRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.FromUnmanagedOverloadsNotSupportedMessage)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.FromUnmanagedOverloadsNotSupportedDescription))); /// public static readonly DiagnosticDescriptor MarshallerTypeMustBeClosedOrMatchArityRule = @@ -390,6 +467,50 @@ public static class DefaultMarshalModeDiagnostics isEnabledByDefault: true, description: GetResourceString(nameof(SR.StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsDescription))); + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresFromManagedRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresFromManagedMessage)), + Category, + DiagnosticSeverity.Info, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresFromManagedDescription))); + + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresToUnmanagedRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresToUnmanagedMessage)), + Category, + DiagnosticSeverity.Info, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresToUnmanagedDescription))); + + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresToManagedRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresToManagedMessage)), + Category, + DiagnosticSeverity.Info, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresToManagedDescription))); + + /// + public static readonly DiagnosticDescriptor StatefulMarshallerRequiresFromUnmanagedRule = + new DiagnosticDescriptor( + Ids.CustomMarshallerTypeMustHaveRequiredShape, + GetResourceString(nameof(SR.CustomMarshallerTypeMustHaveRequiredShapeTitle)), + GetResourceString(nameof(SR.StatefulMarshallerRequiresFromUnmanagedMessage)), + Category, + DiagnosticSeverity.Info, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.StatefulMarshallerRequiresFromUnmanagedDescription))); + internal static DiagnosticDescriptor GetDefaultMarshalModeDiagnostic(DiagnosticDescriptor errorDescriptor) { if (ReferenceEquals(errorDescriptor, CustomMarshallerAttributeAnalyzer.StatelessValueInRequiresConvertToUnmanagedRule)) @@ -416,6 +537,22 @@ internal static DiagnosticDescriptor GetDefaultMarshalModeDiagnostic(DiagnosticD { return StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsRule; } + if (ReferenceEquals(errorDescriptor, CustomMarshallerAttributeAnalyzer.StatefulMarshallerRequiresFromManagedRule)) + { + return StatefulMarshallerRequiresFromManagedRule; + } + if (ReferenceEquals(errorDescriptor, CustomMarshallerAttributeAnalyzer.StatefulMarshallerRequiresToUnmanagedRule)) + { + return StatefulMarshallerRequiresToUnmanagedRule; + } + if (ReferenceEquals(errorDescriptor, CustomMarshallerAttributeAnalyzer.StatefulMarshallerRequiresToManagedRule)) + { + return StatefulMarshallerRequiresToManagedRule; + } + if (ReferenceEquals(errorDescriptor, CustomMarshallerAttributeAnalyzer.StatefulMarshallerRequiresFromUnmanagedRule)) + { + return StatefulMarshallerRequiresFromUnmanagedRule; + } return errorDescriptor; } } @@ -437,7 +574,21 @@ internal static DiagnosticDescriptor GetDefaultMarshalModeDiagnostic(DiagnosticD LinearCollectionOutRequiresCollectionMethodsRule, StatelessLinearCollectionOutRequiresCollectionMethodsRule, StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsRule, - CallerAllocConstructorMustHaveBufferSizeRule, + StatefulMarshallerRequiresFromManagedRule, + StatefulMarshallerRequiresToUnmanagedRule, + StatefulMarshallerRequiresToManagedRule, + StatefulMarshallerRequiresFromUnmanagedRule, + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessValueInRequiresConvertToUnmanagedRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionRequiresTwoParameterAllocateContainerForUnmanagedElementsRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessRequiresConvertToManagedRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionInRequiresCollectionMethodsRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionOutRequiresCollectionMethodsRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatefulMarshallerRequiresFromManagedRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatefulMarshallerRequiresToUnmanagedRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatefulMarshallerRequiresToManagedRule), + DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatefulMarshallerRequiresFromUnmanagedRule), + CallerAllocFromManagedMustHaveBufferSizeRule, MarshallerTypeMustBeClosedOrMatchArityRule, FirstParameterMustMatchReturnTypeRule, ReturnTypesMustMatchRule, @@ -445,12 +596,9 @@ internal static DiagnosticDescriptor GetDefaultMarshalModeDiagnostic(DiagnosticD ElementTypesOfReturnTypesMustMatchRule, ManagedTypeMustBeClosedOrMatchArityRule, ManagedTypeMustBeNonNullRule, - DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessValueInRequiresConvertToUnmanagedRule), - DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionRequiresTwoParameterAllocateContainerForUnmanagedElementsRule), - DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessRequiresConvertToManagedRule), - DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionInRequiresCollectionMethodsRule), - DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionOutRequiresCollectionMethodsRule), - DefaultMarshalModeDiagnostics.GetDefaultMarshalModeDiagnostic(StatelessLinearCollectionRequiresTwoParameterAllocateContainerForManagedElementsRule)); + ElementMarshallerCannotBeStatefulRule, + StatefulMarshallerRequiresFreeRule, + FromUnmanagedOverloadsNotSupportedRule); public override void Initialize(AnalysisContext context) { @@ -580,7 +728,7 @@ void ReportDiagnosticsForMissingMembers(DiagnosticReporter diagnosticReporter) { CheckForBufferSizeMember( diagnosticReporter, - isLinearCollectionMarshaller ? StatelessLinearCollectionCallerAllocConstructorMustHaveBufferSizeRule : CallerAllocConstructorMustHaveBufferSizeRule, + isLinearCollectionMarshaller ? StatelessLinearCollectionCallerAllocFromManagedMustHaveBufferSizeRule : CallerAllocFromManagedMustHaveBufferSizeRule, marshallerType, methods.ToUnmanagedWithBuffer!); } @@ -836,10 +984,246 @@ private bool TryGetElementTypeFromSpanType(ITypeSymbol spanTypeMaybe, [NotNullWh return false; } -#pragma warning disable CA1822 // Mark members as static private void AnalyzeStatefulMarshallerType(DiagnosticReporter diagnosticReporter, ITypeSymbol managedType, MarshalMode mode, INamedTypeSymbol marshallerType, bool isLinearCollectionMarshaller) -#pragma warning restore CA1822 // Mark members as static { + if (mode is MarshalMode.ElementIn + or MarshalMode.ElementRef + or MarshalMode.ElementOut) + { + diagnosticReporter.CreateAndReportDiagnostic(ElementMarshallerCannotBeStatefulRule, marshallerType.ToDisplayString(), mode); + return; + } + + var (shape, methods) = StatefulMarshallerShapeHelper.GetShapeForType(marshallerType, managedType, isLinearCollectionMarshaller, _compilation); + var fromUnmanagedCandidates = StatefulMarshallerShapeHelper.GetFromUnmanagedMethodCandidates(marshallerType); + + bool reportedDiagnostics = false; + DiagnosticReporter trackingReporter = new DiagnosticReporter((descriptor, properties, args) => + { + reportedDiagnostics = true; + diagnosticReporter.CreateAndReportDiagnostic(descriptor, properties, args); + }); + trackingReporter = AdaptReporterForMarshalMode(trackingReporter, mode); + + ReportDiagnosticsForMissingMembers(trackingReporter); + + // If we encountered any missing-member diagnostics, then we'll stop checking for additional errors here. + if (reportedDiagnostics) + return; + + ReportDiagnosticsForMismatchedMemberSignatures(trackingReporter); + + void ReportDiagnosticsForMissingMembers(DiagnosticReporter diagnosticReporter) + { + // If a caller-allocated-buffer convert method exists, verify that the BufferSize property exists + if (shape.HasFlag(MarshallerShape.CallerAllocatedBuffer) && mode == MarshalMode.ManagedToUnmanagedIn) + { + CheckForBufferSizeMember( + diagnosticReporter, + CallerAllocFromManagedMustHaveBufferSizeRule, + marshallerType, + methods.FromManagedWithBuffer!); + } + + if (ManualTypeMarshallingHelper.ModeUsesManagedToUnmanagedShape(mode)) + { + // If the marshaller mode uses the managed->unmanaged shapes, + // verify that we have either a full managed-to-unmanaged shape + // or that our scenario supports the caller-allocated buffer managed-to-unmanaged shape + // and that the caller-allocated-buffer shape is present. + if (!(shape.HasFlag(MarshallerShape.ToUnmanaged) || (mode == MarshalMode.ManagedToUnmanagedIn && shape.HasFlag(MarshallerShape.CallerAllocatedBuffer)))) + { + // Verify that all of the following methods are present with valid shapes: + // - FromManaged + // - ToUnmanaged + if (methods.FromManaged is null && methods.FromManagedWithBuffer is null) + { + diagnosticReporter.CreateAndReportDiagnostic( + StatefulMarshallerRequiresFromManagedRule, + MissingMemberNames.CreateDiagnosticPropertiesForMissingMembersDiagnostic( + mode, + ShapeMemberNames.Value.Stateful.FromManaged), + marshallerType.ToDisplayString(), + mode, + managedType.ToDisplayString()); + } + if (methods.ToUnmanaged is null) + { + diagnosticReporter.CreateAndReportDiagnostic( + StatefulMarshallerRequiresToUnmanagedRule, + MissingMemberNames.CreateDiagnosticPropertiesForMissingMembersDiagnostic( + mode, + ShapeMemberNames.Value.Stateful.ToUnmanaged), + marshallerType.ToDisplayString(), + mode, + managedType.ToDisplayString()); + } + + if (isLinearCollectionMarshaller) + { + // Verify that all of the following methods are present with valid shapes: + // - GetManagedValuesSource + // - GetUnmanagedValuesDestination + List missingCollectionMethods = new(); + if (methods.ManagedValuesSource is null) + { + missingCollectionMethods.Add(ShapeMemberNames.LinearCollection.Stateful.GetManagedValuesSource); + } + if (methods.UnmanagedValuesDestination is null) + { + missingCollectionMethods.Add(ShapeMemberNames.LinearCollection.Stateful.GetUnmanagedValuesDestination); + } + if (missingCollectionMethods.Count > 0) + { + diagnosticReporter.CreateAndReportDiagnostic( + LinearCollectionInRequiresCollectionMethodsRule, + MissingMemberNames.CreateDiagnosticPropertiesForMissingMembersDiagnostic( + mode, + missingCollectionMethods), + marshallerType.ToDisplayString(), + mode, + managedType.ToDisplayString()); + } + } + } + } + + if (ManualTypeMarshallingHelper.ModeUsesUnmanagedToManagedShape(mode)) + { + // If the marshaller mode uses the unmanaged->managed shapes, + // verify that we have a full unmanaged-to-managed shape + if ((shape & (MarshallerShape.ToManaged | MarshallerShape.GuaranteedUnmarshal)) == 0) + { + // Verify that all of the following methods are present with valid shapes: + // - ToManaged or ToManagedFinally + // - FromUnmanaged + if (methods.ToManaged is null && methods.ToManagedGuaranteed is null) + { + diagnosticReporter.CreateAndReportDiagnostic( + StatefulMarshallerRequiresToManagedRule, + MissingMemberNames.CreateDiagnosticPropertiesForMissingMembersDiagnostic( + mode, + ShapeMemberNames.Value.Stateful.ToManaged), + marshallerType.ToDisplayString(), + mode, + managedType.ToDisplayString()); + } + + if (fromUnmanagedCandidates.Length == 0) + { + diagnosticReporter.CreateAndReportDiagnostic( + StatefulMarshallerRequiresFromUnmanagedRule, + MissingMemberNames.CreateDiagnosticPropertiesForMissingMembersDiagnostic( + mode, + ShapeMemberNames.Value.Stateful.FromUnmanaged), + marshallerType.ToDisplayString(), + mode, + managedType.ToDisplayString()); + } + + if (fromUnmanagedCandidates.Length > 1) + { + diagnosticReporter.CreateAndReportDiagnostic( + FromUnmanagedOverloadsNotSupportedRule, + marshallerType.ToDisplayString()); + } + + if (isLinearCollectionMarshaller) + { + // Verify that all of the following methods are present with valid shapes: + // - GetUnmanagedValuesSource + // - GetManagedValuesDestination + List missingCollectionMethods = new(); + if (methods.UnmanagedValuesSource is null) + { + missingCollectionMethods.Add(ShapeMemberNames.LinearCollection.Stateful.GetUnmanagedValuesSource); + } + if (methods.ManagedValuesDestination is null) + { + missingCollectionMethods.Add(ShapeMemberNames.LinearCollection.Stateful.GetManagedValuesDestination); + } + if (missingCollectionMethods.Count > 0) + { + diagnosticReporter.CreateAndReportDiagnostic( + LinearCollectionOutRequiresCollectionMethodsRule, + MissingMemberNames.CreateDiagnosticPropertiesForMissingMembersDiagnostic( + mode, + missingCollectionMethods), + marshallerType.ToDisplayString(), + mode, + managedType.ToDisplayString()); + } + } + } + } + + if (methods.Free is null) + { + diagnosticReporter.CreateAndReportDiagnostic( + StatefulMarshallerRequiresFreeRule, + MissingMemberNames.CreateDiagnosticPropertiesForMissingMembersDiagnostic( + mode, + ShapeMemberNames.Free), + marshallerType.ToDisplayString()); + } + } + + void ReportDiagnosticsForMismatchedMemberSignatures(DiagnosticReporter diagnosticReporter) + { + // Verify that the unmanaged type used by the marshaller is consistently + // the same in all of the methods that use the unmanaged type. + // Also, verify that the collection element types are consistent. + ITypeSymbol? unmanagedType = null; + if (ManualTypeMarshallingHelper.ModeUsesManagedToUnmanagedShape(mode)) + { + // First verify all usages in the managed->unmanaged shape. + unmanagedType = methods.ToUnmanaged.ReturnType; + if (!unmanagedType.IsUnmanagedType && !unmanagedType.IsStrictlyBlittable()) + { + diagnosticReporter.CreateAndReportDiagnostic(UnmanagedTypeMustBeUnmanagedRule, methods.ToUnmanaged.ToDisplayString()); + } + } + + if (ManualTypeMarshallingHelper.ModeUsesUnmanagedToManagedShape(mode)) + { + // Verify the unmanaged types match unmanaged->managed shape + IMethodSymbol fromUnmanagedMethod = fromUnmanagedCandidates[0]; + if (unmanagedType is not null && !SymbolEqualityComparer.Default.Equals(unmanagedType, fromUnmanagedMethod.Parameters[0].Type)) + { + // If both shapes are present, verify that the unmanaged types match + diagnosticReporter.CreateAndReportDiagnostic(FirstParameterMustMatchReturnTypeRule, fromUnmanagedMethod.ToDisplayString(), methods.ToUnmanaged.ToDisplayString()); + } + else + { + unmanagedType = fromUnmanagedMethod.Parameters[0].Type; + + if (!unmanagedType.IsUnmanagedType && !unmanagedType.IsStrictlyBlittable()) + { + diagnosticReporter.CreateAndReportDiagnostic(UnmanagedTypeMustBeUnmanagedRule, fromUnmanagedMethod.ToDisplayString()); + } + } + } + + // Verify that the managed collection element types match. + // Verify that the unmanaged collection types have the expected element types. + if (isLinearCollectionMarshaller) + { + if (methods.ManagedValuesSource is not null && methods.ManagedValuesDestination is not null) + { + if (TryGetElementTypeFromSpanType(methods.ManagedValuesSource.ReturnType, out ITypeSymbol sourceElementType) + && TryGetElementTypeFromSpanType(methods.ManagedValuesDestination.ReturnType, out ITypeSymbol destinationElementType) + && !SymbolEqualityComparer.Default.Equals(sourceElementType, destinationElementType)) + { + diagnosticReporter.CreateAndReportDiagnostic(ElementTypesOfReturnTypesMustMatchRule, methods.ManagedValuesSource.ToDisplayString(), methods.ManagedValuesDestination.ToDisplayString()); + } + } + + var (typeArguments, _) = marshallerType.GetAllTypeArgumentsIncludingInContainingTypes(); + ITypeSymbol expectedUnmanagedCollectionElementType = typeArguments[typeArguments.Length - 1]; + VerifyUnmanagedCollectionElementType(diagnosticReporter, methods.UnmanagedValuesSource, expectedUnmanagedCollectionElementType, _readOnlySpanOfT); + VerifyUnmanagedCollectionElementType(diagnosticReporter, methods.UnmanagedValuesDestination, expectedUnmanagedCollectionElementType, _spanOfT); + } + } } } } 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 68a85848d4899..8224ad74f4b73 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx @@ -117,16 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' @@ -375,7 +375,7 @@ Overloading the 'FromUnmanaged' method is unuspported as some shapes are unable to distinguish between overloads. - Overloading the 'FromUnmanaged' method is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers The return type of 'ConvertToUnmanaged' and the parameter type of 'ConvertToManaged' must be the same. @@ -443,6 +443,12 @@ The element type of the span returned by '{0}' must be the same type as the element type of the span returned by '{1}'. + + A marshaller for an element scenario cannot be stateful. + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + LibraryImportAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. @@ -452,6 +458,36 @@ LibraryImportAttribute requires unsafe code. + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + Convert to 'LibraryImport' and enable unsafe code @@ -461,4 +497,4 @@ Convert to 'LibraryImport' with '{0}' suffix and enable unsafe code - \ No newline at end of file + 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 6347b0ad41e4a..533d6cfcc411b 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 @@ -7,12 +7,12 @@ Přidat chybějící vlastní typu zařazovacích členů - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Pokud se obrazec „Ze spravovaných na nespravované s vyrovnávací pamětí přidělenou volajícímu“ používá metodou FromManaged, která přebírá Span<T> u zařazovacího typu, musí typ poskytovat statickou vlastnost BufferSize, která určuje počet elementů ve vyrovnávací paměti přidělené volajícímu. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' Zařazovací typ {0} musí obsahovat statickou celočíselnou vlastnost BufferSize určenou jen pro čtení, která určuje velikost vyrovnávací paměti přidělené volajícímu, protože obsahuje metodu FromManaged, která přebírá Span<{1}> přidělený volajícímu. @@ -117,6 +117,16 @@ Zařazovací typ nemá požadovaný tvar + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - Přetížení metody FromUnmanaged není u vlastního zařazování podporováno. + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ The return type of '{0}' must be the same type as the return type of '{1}' - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' 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 7b1264cf31f3d..8096f6b1edbcf 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 @@ -7,12 +7,12 @@ Hinzufügen fehlender benutzerdefinierter Marshallermember - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Wenn die Form "Verwaltet bis nicht verwaltet mit Caller-Allocated Buffer" verwendet wird, indem eine Methode "FromManaged" bereitgestellt wird, die eine "Span<T>" für den Marshallertyp akzeptiert, muss der Typ eine statische Eigenschaft "BufferSize" bereitstellen, um die Anzahl von Elementen im vom Aufrufer zugewiesenen Puffer anzugeben. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' Der Marshallertyp "{0}" muss eine statische schreibgeschützte "int"-Eigenschaft "BufferSize" aufweisen, um die Größe des vom Aufrufer zugewiesenen Puffers anzugeben, da er eine FromManaged-Methode aufweist, die eine vom Aufrufer zugewiesene "Span<{1}>" akzeptiert @@ -117,6 +117,16 @@ Der Marshaller-Typ weist nicht die erforderliche Form auf + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - Das Überladen der Methode "FromUnmanaged" wird in benutzerdefinierten Marshallern nicht unterstützt + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ The return type of '{0}' must be the same type as the return type of '{1}' - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' 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 b1f0436b833fd..a35812f21c00a 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 @@ -7,12 +7,12 @@ Agregue los miembros de serializador de tipo personalizado que faltan - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Cuando la forma "Administrado a no administrado con búfer asignado por el llamador" se usa con un método "FromManaged" que toma un "Span<T>" en el tipo de serializador, el tipo debe proporcionar una propiedad estática "BufferSize" para proporcionar el número de elementos en el búfer asignado por el llamador. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' El tipo de serializador "{0}" debe tener una propiedad "int" "BufferSize" estática de solo lectura para especificar el tamaño del búfer asignado por el autor de la llamada porque tiene un método FromManaged que toma una propiedad "Span<{1}>" asignada por el autor de la llamada. @@ -117,6 +117,16 @@ El tipo de serializador no tiene la forma necesaria + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. El tipo de elemento del intervalo devuelto por el primer método debe ser del mismo tipo que el tipo de elemento del intervalo devuelto por el segundo método. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - No se admite la sobrecarga del método "FromUnmanaged" en los serializadores personalizados + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ El tipo de valor devuelto de "{0}" debe ser del mismo tipo que el tipo de valor devuelto de "{1}" - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Cuando la forma "Administrado a no administrado con búfer asignado por el llamador" se usa con un método "AllocateContainerForUnmanagedElements" que toma un "Span<T>" en el tipo de serializador, el tipo debe proporcionar una propiedad estática "BufferSize" para proporcionar el número de elementos en el búfer asignado por el llamador. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' El tipo de serializador "{0}" debe tener una propiedad "int" "BufferSize" estática de solo lectura para especificar el tamaño del búfer asignado por el autor de la llamada porque tiene un método "AllocateContainerForUnmanagedElements" que toma una propiedad "Span<{1}>" 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 1963d0a5b676e..1b5c292a026a6 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 @@ -7,12 +7,12 @@ Ajouter les membres du marshaleur de type personnalisé manquants - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Lorsque la forme « Managée à non managée avec mémoire tampon allouée par l’appelant » est utilisée en fournissant une méthode « FromManaged » qui prend un « Span<T> » sur le type marshaler, le type doit fournir une propriété « BufferSize » statique pour fournir le nombre d’éléments dans la mémoire tampon allouée par l’appelant. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' Le type de marshaleur « {0} » doit avoir une propriété « BufferSize » en lecture seule « int » statique pour spécifier la taille de la mémoire tampon allouée par l’appelant, car elle a une méthode FromManaged qui accepte un « Span<{1}> » alloué par l’appelant @@ -117,6 +117,16 @@ Le type Marshaller n’a pas la forme requise + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. Le type d’élément de l’étendue retournée par la première méthode doit être du même type que le type d’élément de l’étendue retournée par la deuxième méthode. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - La surcharge de la méthode « FromUnmanaged » n’est pas prise en charge dans les marshaleurs personnalisés + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ Le type de retour de '{0}' doit être le même que le type de retour de '{1}' - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Lorsque la forme 'Managée à non managée avec mémoire tampon allouée par l’appelant' est utilisée en fournissant une méthode 'AllocateContainerForUnmanagedElements' qui prend un 'Span<T>' sur le type marshaler, le type doit fournir une propriété 'BufferSize' statique pour fournir le nombre d’éléments dans la mémoire tampon allouée par l’appelant. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' Le type marshaleur '{0}' doit avoir une propriété 'int' 'BufferSize' statique en lecture seule pour spécifier la taille de la mémoire tampon allouée par l’appelant, car elle a une méthode 'AllocateContainerForUnmanagedElements' qui accepte un 'Span<{1}>' alloué par l’appelant 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 7a6296cb55a67..1a9361432ac47 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 @@ -7,12 +7,12 @@ Aggiungi membri mancanti del gestore del marshalling di tipi personalizzato mancanti - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Quando si usa la forma 'Managed to Unmanaged with Caller-Allocated Buffer', fornendo un metodo "FromManaged" che accetta un elemento "Span<T>" per il tipo di marshaller, il tipo deve fornire una proprietà statica "BufferSize" per fornire il numero di elementi nel buffer allocato dal chiamante. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' Il tipo di marshaller '{0}' deve avere una proprietà 'int' 'BufferSize' di sola lettura statica per specificare le dimensioni del buffer allocato dal chiamante perché dispone di un metodo FromManaged che accetta un elemento 'Span<{1}>' allocato dal chiamante @@ -117,6 +117,16 @@ Il tipo di marshaller non ha la forma richiesta + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. Il tipo di elemento dell'intervallo restituito dal primo metodo deve essere dello stesso tipo del tipo di elemento dell'intervallo restituito dal secondo metodo. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - L'overload del metodo 'FromUnmanaged' non è supportato nei marshaller personalizzati + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ Il tipo restituito di '{0}' deve essere dello stesso tipo restituito di '{1}' - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Quando si usa la forma 'Managed to Unmanaged with Caller-Allocated Buffer', fornendo un metodo 'AllocateContainerForUnmanagedElements' che accetta un elemento "Span<T>" per il tipo di marshaller, il tipo deve fornire una proprietà statica "BufferSize" per fornire il numero di elementi nel buffer allocato dal chiamante. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' Il tipo di marshaller '{0}' deve avere una proprietà 'int' 'BufferSize' di sola lettura statica per specificare le dimensioni del buffer allocato dal chiamante perché dispone di un metodo 'AllocateContainerForUnmanagedElements' che accetta un elemento 'Span<{1}>' allocato dal chiamante 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 c91c769f7d01e..d19c78a0f97fc 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 @@ -7,12 +7,12 @@ 不足しているカスタム型マーシャラー メンバーの追加 - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. マーシャラー型で 'Span<T>' を取る 'FromManaged' メソッドを指定して 'Managed to Unmanaged with Caller-Allocated Buffer' 図形を使用する場合、呼び出し元に割り当てられたバッファー内の要素の数を提供するには、静的な 'BufferSize' プロパティを型で指定する必要があります。 - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' マーシャラー型 '{0}' には、呼び出し元が割り当てた 'Span<{1}>' を受け取る FromManaged メソッドがあるため、呼び出し元が割り当てたバッファーのサイズを指定するには、静的な読み取り専用の 'int' 'BufferSize' プロパティが必要です @@ -117,6 +117,16 @@ マーシャラー型に必要な図形がありません + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. 最初のメソッドによって返されるスパンの要素型は、2 番目のメソッドによって返されるスパンの要素型と同じ型である必要があります。 @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - 'FromUnmanaged' メソッドのオーバーロードは、カスタム マーシャラーではサポートされていません + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ 戻り値の型 '{0}' は、戻り値の型 '{1}' と同じである必要があります - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. マーシャラー型の 'Span<T>' を受け取る 'AllocateContainerForUnmanagedElements' メソッドを指定して 'Managed to Unmanaged with Caller-Allocated Buffer' シェイプを使用する場合、型は静的な 'BufferSize' プロパティを提供して、発信元が割り当てたバッファー内の要素数を提供する必要があります。 - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' マーシャラー型 '{0}' には、発信元が割り当てたバッファーのサイズを指定するために、静的な読み取り専用の 'int' 'BufferSize' プロパティが必要です、なぜなら 発信元が割り当てた 'Span<{1}>' を受け取る 'AllocateContainerForUnmanagedElements' メソッドがあるからです 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 1f6988ad4c753..ee546a11bd2e0 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 @@ -7,12 +7,12 @@ 누락된 사용자 지정 형식 마샬러 구성원 추가 - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. 마샬러 형식에서 'Span<T>'을 사용하는 'FromManaged' 메서드를 제공하여 '호출자 할당 버퍼로 관리되지 않음' 셰이프를 사용하는 경우 형식은 숫자를 제공하기 위해 정적 'BufferSize' 속성을 제공해야 합니다. 호출자 할당 버퍼의 요소 수 - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' 마샬러 유형 '{0}'에는 호출자 할당 'Span<{1}>'를 사용하는 FromManaged 메서드가 있으므로 호출자 할당 버퍼의 크기를 지정하려면 정적 읽기 전용 'int' 'BufferSize' 속성이 있어야 합니다. @@ -117,6 +117,16 @@ 마샬러 형식에 필요한 셰이프가 없습니다. + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. 첫 번째 메서드에서 반환된 범위의 요소 형식은 두 번째 메서드에서 반환된 범위의 요소 형식과 같은 형식이어야 합니다. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - 사용자 지정 마샬러에서는 'FromUnmanaged' 메서드 오버로드가 지원되지 않습니다. + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ '{0}' 반환 형식은 '{1}' 반환 형식과 같아야 합니다. - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. 마샬러 형식에서 'Span<T>'을 사용하는 'AllocateContainerForUnmanagedElements' 메서드를 제공하여 '호출자 할당 버퍼로 관리되지 않음' 셰이프를 사용하는 경우 형식은 호출자 할당 버퍼의 요소 수를 제공하기 위해 정적 'BufferSize' 속성을 제공해야 합니다. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' 마샬러 유형 '{0}'에는 호출자 할당 'Span<{1}>'을 사용하는 'AllocateContainerForUnmanagedElements' 메서드가 있으므로 호출자 할당 버퍼의 크기를 지정하려면 정적 읽기 전용 'int' 'BufferSize' 속성이 있어야 합니다. 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 05f3bad641fdb..2a31b0db547b0 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 @@ -7,12 +7,12 @@ Dodaj brakujące składowe elementu przeprowadzającego marshalling typu niestandardowego - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Gdy kształt „Zarządzane do niezarządzanego za pomocą buforu przydzielonego przez wywołującego” jest używany przez podanie metody „FromManaged”, która przyjmuje element „Span< T>” w typie marshallera, typ musi udostępniać statyczną właściwość „BufferSize”, aby podać liczbę elementów w buforze przydzielonym przez wywołującego. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' Typ marshallera „{0}” musi mieć statyczną właściwość „int” „BufferSize” tylko do odczytu, aby określić rozmiar buforu przydzielonego przez wywołującego, ponieważ ma metodę FromManaged, która przyjmuje przydzielony przez wywołującego element „Span<{1}>” @@ -117,6 +117,16 @@ Typ marshallera nie ma wymaganego kształtu + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - Przeciążanie metody „FromUnmanaged” nie jest obsługiwane w niestandardowych marshallerach + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ The return type of '{0}' must be the same type as the return type of '{1}' - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' 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 2786d76a64152..be6f6e7e1ab21 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 @@ -7,12 +7,12 @@ Adicionar membros marshaller de tipo personalizado ausentes - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Quando a forma 'Managed to Unmanaged com Caller-Allocated Buffer' é usada fornecendo um método 'FromManaged' que usa um 'Span<T>' no tipo de empacotador, o tipo deve fornecer uma propriedade estática 'BufferSize' para fornecer o número de elementos no buffer alocado pelo chamador. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' O tipo de empacotador '{0}' deve ter uma propriedade estática somente leitura 'int' 'BufferSize' para especificar o tamanho do buffer alocado pelo chamador porque ele tem um método FromManaged que recebe um 'Span' alocado pelo chamador<{1}>' @@ -117,6 +117,16 @@ O tipo de marshaller não tem a forma necessária + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. O tipo de elemento do intervalo retornado pelo primeiro método deve ser do mesmo tipo que o tipo de elemento da extensão retornada pelo segundo método. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - A sobrecarga do método 'FromUnmanaged' não é compatível com empacotadores personalizados + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ O tipo de retorno de “{0}” deve ser do mesmo tipo que o tipo de retorno “{1}” - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Quando a forma 'Managed to Unmanaged with Caller-Allocated Buffer' é usada fornecendo um método 'AllocateContainerForUnmanagedElements' que usa um 'Span<T>' no tipo de marshaller, o tipo deve fornecer uma propriedade estática 'BufferSize' para fornecer o número de elementos no buffer alocado pelo chamador. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' O tipo de marshaller “{0}” deve ter uma propriedade estática somente leitura 'int' 'BufferSize' para especificar o tamanho do buffer alocado pelo chamador porque ele tem um método 'AllocateContainerForUnmanagedElements' que recebe um 'Span' alocado pelo chamador<{1}>' 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 9281b481f2334..495696721027b 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 @@ -7,12 +7,12 @@ Добавить отсутствующие элементы маршалатора настраиваемого типа - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Если фигура "Из управляемого в неуправляемый с буфером, выделяемым вызывающим объектом" используется путем предоставления метода "FromManaged", выполняющего "Span<T>" для типа маршалера, этот тип должен предоставлять статическое свойство "BufferSize", чтобы предоставить количество элементов в буфере, выделенном вызывающим объектом. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' У типа маршалера "{0}" должно быть статическое доступное только для чтения свойство "BufferSize" со значением типа "int", чтобы указывать размер буфера, выделенного вызывающим объектом, поскольку у этого типа есть метод FromManaged, выполняющий "Span<{1}>", выделяемый вызывающим объектом. @@ -117,6 +117,16 @@ Тип маршалера не имеет требуемой фигуры + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. Тип элемента диапазона, возвращаемого первым методом, должен быть того же типа, что и тип элемента диапазона, возвращаемого вторым методом. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - Перегрузка метода "FromUnmanaged" не поддерживается в настраиваемых маршалерах + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ Тип возвращаемого значения "{0}" должен быть тем же, что и тип возвращаемого значения "{1}" - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Когда форма "Управляемый в неуправляемый с буфером, выделенным вызывающим объектом" используется путем предоставления метода "AllocateContainerForUnmanagedElements", принимающим "Span<T>" для типа маршаллера, тип должен предоставлять статическое свойство "BufferSize", чтобы предоставить число элементов в выделенном вызывающей стороне буфере. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' У типа маршалера "{0}" должно быть статическое свойство "int" "BufferSize" только для чтения, чтобы указать размер буфера, выделенного вызывающей стороной, поскольку он имеет метод "AllocateContainerForUnmanagedElements", принимающий выделенную вызывающей стороной область "Span<{1}>" 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 f785683b1e5ab..498d1646572d1 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 @@ -7,12 +7,12 @@ Eksik olan özel tür sıralayıcı üyelerini ekleyin - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Hazırlayıcı türünde 'Span<T>' alan bir 'FromManaged' yöntemi sağlanarak 'Çağıran Tarafından Ayrılan Arabellek ile Yönetilenden Yönetilmeyene' şekli kullanıldığında tür, çağıran tarafından ayrılan arabellekteki öğe sayısını sağlamak için statik bir 'BufferSize' özelliği belirtmelidir. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' Hazırlayıcı türü '{0}', çağıran tarafından ayrılan arabelleğin boyutunu belirtmek için statik bir salt okunur 'int' 'BufferSize' özelliğine sahip olmalıdır çünkü çağıran tarafından ayrılan 'Span<{1}>' alan bir 'FromManaged' yöntemine sahiptir. @@ -117,6 +117,16 @@ Sıralayıcı türü gerekli şekle sahip değil + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. İlk yöntem tarafından döndürülen yayılım öğe türü, ikinci metot tarafından döndürülen yayılım öğe türüyle aynı olmalıdır. @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - 'FromUnmanaged' yönteminin aşırı yüklemesi özel hazırlayıcılarda desteklenmez. + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ '{0}' öğesinin dönüş türü, '{1}' öğesinin dönüş türüyle aynı olmalıdır - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. Sıralayıcı türünde 'Span<T>' alan bir 'AllocateContainerForUnmanagedElements' yöntemi sağlanarak 'Çağıran Tarafından Ayrılan Arabellek ile Yönetilenden Yönetilmeyene' şekli kullanıldığında tür, çağıran tarafından ayrılan arabellekteki öğe sayısını sağlamak için statik bir 'BufferSize' özelliği belirtmelidir. - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' '{0}' sıralayıcı türü, çağıran tarafından ayrılan arabelleğin boyutunu belirtmek için statik bir salt okunur 'int' 'BufferSize' özelliğine sahip olmalıdır çünkü çağıran tarafından ayrılan 'Span<{1}>' alan bir 'AllocateContainerForUnmanagedElements' yöntemine sahiptir. 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 946c30c9f9fef..5b8b64873d44a 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 @@ -7,12 +7,12 @@ 添加缺少的自定义类型封送程序成员 - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. 如果通过提供从封送处理程序类型提取“Span<T>”的“FromManaged”方法来使用“Managed to Unmanaged with Caller-Allocated Buffer”形状,则该类型必须提供一个静态的“BufferSize”属性才能提供已分配调用方缓冲。 - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' 封送处理程序类型“{0}”必须拥有静态的只读“int”“BufferSize”属性,才能指定已分配调用方缓冲的大小,因为它具有提取已分配调用方“Span<{1}>”的 FromManaged 方法 @@ -117,6 +117,16 @@ 封送程序类型没有必需的形状 + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. 第一个方法返回的跨度的元素类型必须与第二个方法返回的跨度的元素类型为相同的类型。 @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - 自定义封送处理程序中不支持重载“FromUnmanaged”方法 + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ “{0}”的返回类型必须与“{1}”的返回类型为相同的类型 - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. 如果在封送程序类型上提供采用“Span<T>”的“AllocateContainerForUnmanagedElements”方法以使用“通过调用方分配的缓冲区从托管到非托管”形状,则该类型必须提供静态“BufferSize”属性以提供调用方分配的缓冲区中的元素数。 - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' 封送程序类型“{0}”必须具有静态只读“int”“BufferSize”属性以指定调用方分配的缓冲区的大小,因为它具有采用调用方分配的“Span<{1}>”的“AllocateContainerForUnmanagedElements”方法 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 3fc130c2dcf22..5d4fcaabf218f 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 @@ -7,12 +7,12 @@ 新增遺漏的自訂類型排列器成員 - + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing a 'FromManaged' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. 當透過提供在封送處理器類型上採用 'Span<T>' 的 'FromManaged' 方法來使用 'Managed to Unmanaged with Caller-Allocated Buffer' 圖形時,該類型必須提供靜態 'BufferSize' 屬性以提供 caller-allocated 緩衝區中的元素數字。 - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has a FromManaged method that takes a caller-allocated 'Span<{1}>' 封送處理器類型 '{0}' 必須有靜態唯讀 'int' 'BufferSize' 屬性,以指定 caller-allocated 緩衝區的大小,因為它具有採用 caller-allocated 'Span<{1}>' 的 FromManaged 方法 @@ -117,6 +117,16 @@ 封送處理器類型沒有必要的圖形 + + A marshaller for an element scenario cannot be stateful. + A marshaller for an element scenario cannot be stateful. + + + + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + The specified marshaller type '{0}' is a stateful marshaller, but stateful marshallers are not allowed in the provided marshal mode '{1}' + + The element type of the span returned by the first method must be the same type as the element type of the span returned by the second method. 第一個方法傳回之跨距的元素類型必須與第二個方法傳回之跨距的元素類型相同類型。 @@ -163,8 +173,8 @@ - Overloading the 'FromUnmanaged' method is not supported in custom marshallers - 自訂封送處理器中不支援多載 'FromUnmanaged' 方法 + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers + The type '{0}' overloads the 'FromUnmanaged' method, which is not supported in custom marshallers @@ -387,12 +397,62 @@ '{0}' 的傳回類型必須與 '{1}' 的傳回類型相同 - + + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + A stateful marshaller must have a zero-parameter void-returning instance method named 'Free'. + + + + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + The type '{0}' is a stateful marshaller and does not have a zero-parameter void-returning instance method named 'Free' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'FromManaged' instance method that takes the managed value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromManaged' that takes a '{2}' as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'FromUnmanaged' instance method that takes the unmanaged value as a parameter and returns 'void'. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a one-parameter instance method named 'FromUnmanaged' that takes the 'unmanaged' value as a parameter and returns 'void' + + + + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + A stateful marshaller that supports marshalling from unmanaged to managed must provide a 'ToManaged' instance method that takes no parameters and returns the managed type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToManaged' that returns '{2}' + + + + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + A stateful marshaller that supports marshalling from managed to unmanaged must provide a 'ToUnmanaged' instance method that takes no parameters and returns the 'unmanaged' type. + + + + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + The type '{0}' specifies that it supports the '{1}' marshal mode for '{2}' but it does not provide a zero-parameter instance method named 'ToUnmanaged' that returns the 'unmanaged' type for the marshaller + + + When the 'Managed to Unmanaged with Caller-Allocated Buffer' shape is used by providing an 'AllocateContainerForUnmanagedElements' method that takes a 'Span<T>' on the marshaller type, the type must provide a static 'BufferSize' property to provide the number of elements in the caller-allocated buffer. 當透過提供在封送處理程式類型上採用 'Span<T>' 的 'AllocateContainerForUnmanagedElements' 方法來使用 'Managed to Unmanaged with Caller-Allocated Buffer' 圖形時,該類型必須提供靜態 'BufferSize' 屬性以提供 caller-allocated 緩衝區中的元素數目。 - + The marshaller type '{0}' must have a static read-only 'int' 'BufferSize' property to specify the size of the caller-allocated buffer because it has an 'AllocateContainerForUnmanagedElements' method that takes a caller-allocated 'Span<{1}>' 封送處理程式類型 '{0}' 必須有靜態唯讀 'int' 'BufferSize' 屬性,以指定 caller-allocated 緩衝區的大小,因為它具有採用 caller-allocated 'Span<{1}>' 的 'AllocateContainerForUnmanagedElements' 方法 diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CollectionTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CollectionTests.cs index a991f6bea6940..48d592735280c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CollectionTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CollectionTests.cs @@ -165,6 +165,7 @@ public List ToManagedFinally() public Span GetManagedValuesDestination(int length) => default; public ReadOnlySpan GetUnmanagedValuesSource(int length) => default; public void FromUnmanaged(byte* value) { } + public void Free() {} } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs index 791f6d651d4eb..4608a11b6a2d3 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/CustomMarshallingTests.cs @@ -102,6 +102,8 @@ public int ToManagedFinally() } public void FromUnmanaged(int value) { } + + public void Free() {} } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulLinearCollectionShapeValidation.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulLinearCollectionShapeValidation.cs new file mode 100644 index 0000000000000..0ad27bb6b2f8e --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulLinearCollectionShapeValidation.cs @@ -0,0 +1,457 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.Interop; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xunit; +using static Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer; + +using VerifyCS = LibraryImportGenerator.UnitTests.Verifiers.CSharpCodeFixVerifier< + Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer, + Microsoft.Interop.Analyzers.CustomMarshallerAttributeFixer>; + +namespace LibraryImportGenerator.UnitTests +{ + [ActiveIssue("https://github.com/dotnet/runtime/issues/60650", TestRuntimes.Mono)] + public class CustomMarshallerAttributeAnalyzerTests_StatefulLinearCollectionShapeValidation + { + [Fact] + public async Task ModeThatUsesManagedToUnmanagedShape_Missing_AllMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(0).WithArguments("MarshallerType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromManagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromManagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToUnmanagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToUnmanagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(1).WithArguments("MarshallerType")); + } + + [Fact] + public async Task ModeThatUsesManagedToUnmanagedShape_Missing_ContainerMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m) {} + public nint ToUnmanaged() => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType")); + } + + [Fact] + public async Task ModeThatUsesManagedToUnmanagedShape_Missing_GetManagedValuesSource_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m) {} + public nint ToUnmanaged() => default; + public void Free() {} + public Span GetUnmanagedValuesDestination() => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType")); + } + + [Fact] + public async Task ModeThatUsesManagedToUnmanagedShape_Missing_GetUnmanagedValuesDestination_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m) {} + public nint ToUnmanaged() => default; + public void Free() {} + public ReadOnlySpan GetManagedValuesSource() => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionInRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType")); + } + + [Fact] + public async Task ModeThatUsesManagedToUnmanagedShape_DoesNotReportDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof(MarshallerType<>))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof(MarshallerType<>))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m) {} + public nint ToUnmanaged() => default; + public void Free() {} + public ReadOnlySpan GetManagedValuesSource() => default; + public Span GetUnmanagedValuesDestination() => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source); + } + + + [Fact] + public async Task ModeThatUsesManagedToUnmanagedShape_InvalidCollectionElementType_DoesNotReportDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m) {} + public nint ToUnmanaged() => default; + public void Free() {} + public ReadOnlySpan GetManagedValuesSource() => default; + public Span GetUnmanagedValuesDestination() => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(ReturnTypeMustBeExpectedTypeRule).WithLocation(0).WithArguments("MarshallerType.GetUnmanagedValuesDestination()", "System.Span"), + VerifyCS.Diagnostic(ReturnTypeMustBeExpectedTypeRule).WithLocation(1).WithArguments("MarshallerType.GetUnmanagedValuesDestination()", "System.Span")); + } + + [Fact] + public async Task ModeThatUsesUnmanagedToManagedShape_Missing_AllMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedIn, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(0).WithArguments("MarshallerType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToManagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToManagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromUnmanagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromUnmanagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(1).WithArguments("MarshallerType")); + } + + [Fact] + public async Task ModeThatUsesUnmanagedToManagedShape_Missing_ContainerMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedIn, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromUnmanaged(int f) {} + public ManagedType ToManaged() => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType")); + } + + [Fact] + public async Task ModeThatUsesUnmanagedToManagedShape_Missing_GetUnmanagedValuesSource_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedIn, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromUnmanaged(int f) {} + public ManagedType ToManaged() => default; + public void Free() {} + public Span GetManagedValuesDestination(int numElements) => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType")); + } + + [Fact] + public async Task ModeThatUsesUnmanagedToManagedShape_Missing_GetManagedValuesDestination_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedIn, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromUnmanaged(int f) {} + public ManagedType ToManaged() => default; + public void Free() {} + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType"), + VerifyCS.Diagnostic(LinearCollectionOutRequiresCollectionMethodsRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType")); + } + + [Fact] + public async Task ModeThatUsesUnmanagedToManagedShape_DoesNotReportDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof(MarshallerType<>))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedIn, typeof(MarshallerType<>))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromUnmanaged(int f) {} + public ManagedType ToManaged() => default; + public void Free() {} + public Span GetManagedValuesDestination(int numElements) => default; + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source); + } + + [Fact] + public async Task ModeThatUsesUnmanagedToManagedShape_InvalidCollectionElementType_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedIn, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromUnmanaged(int f) {} + public ManagedType ToManaged() => default; + public void Free() {} + public Span GetManagedValuesDestination(int numElements) => default; + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(ReturnTypeMustBeExpectedTypeRule).WithLocation(0).WithArguments("MarshallerType.GetUnmanagedValuesSource(int)", "System.ReadOnlySpan"), + VerifyCS.Diagnostic(ReturnTypeMustBeExpectedTypeRule).WithLocation(1).WithArguments("MarshallerType.GetUnmanagedValuesSource(int)", "System.ReadOnlySpan")); + } + + [Fact] + public async Task CallerAllocatedBuffer_NoBufferSize_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m, Span buffer) {} + public nint ToUnmanaged() => default; + public void Free() {} + public ReadOnlySpan GetManagedValuesSource() => default; + public Span GetUnmanagedValuesDestination() => default; + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(CallerAllocFromManagedMustHaveBufferSizeRule).WithLocation(0).WithArguments("MarshallerType", "byte")); + } + + [Fact] + public async Task ModeThatUsesBidirectionalShape_DoesNotReportDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedRef, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedRef, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m) {} + public nint ToUnmanaged() => default; + public ReadOnlySpan GetManagedValuesSource() => default; + public Span GetUnmanagedValuesDestination() => default; + public void FromUnmanaged(nint i) {} + public ManagedType ToManaged() => default; + public Span GetManagedValuesDestination(int numElements) => default; + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync(source); + } + + [Fact] + public async Task ModeThatUsesBidirectionalShape_MismatchedManagedElementTypes_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedRef, typeof({|#0:MarshallerType<>|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedRef, typeof({|#1:MarshallerType<>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(ManagedType m) {} + public nint ToUnmanaged() => default; + public ReadOnlySpan GetManagedValuesSource() => default; + public Span GetUnmanagedValuesDestination() => default; + public void FromUnmanaged(nint i) {} + public ManagedType ToManaged() => default; + public Span GetManagedValuesDestination(int numElements) => default; + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync(source, + VerifyCS.Diagnostic(ElementTypesOfReturnTypesMustMatchRule).WithLocation(0).WithArguments("MarshallerType.GetManagedValuesSource()", "MarshallerType.GetManagedValuesDestination(int)"), + VerifyCS.Diagnostic(ElementTypesOfReturnTypesMustMatchRule).WithLocation(1).WithArguments("MarshallerType.GetManagedValuesSource()", "MarshallerType.GetManagedValuesDestination(int)")); + } + + [Fact] + public async Task ModeThatUsesBidirectionalShape_ArrayTarget_DoesNotReportDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + [CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.ManagedToUnmanagedRef, typeof({|#0:MarshallerType<,>|}))] + [CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.UnmanagedToManagedRef, typeof({|#1:MarshallerType<,>|}))] + [ContiguousCollectionMarshaller] + struct MarshallerType + { + public void FromManaged(T[] m) {} + public nint ToUnmanaged() => default; + public ReadOnlySpan GetManagedValuesSource() => default; + public Span GetUnmanagedValuesDestination() => default; + public void FromUnmanaged(nint i) {} + public T[] ToManaged() => default; + public Span GetManagedValuesDestination(int numElements) => default; + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync(source); + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulValueShapeValidation.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulValueShapeValidation.cs new file mode 100644 index 0000000000000..f3e6710d8bf8c --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatefulValueShapeValidation.cs @@ -0,0 +1,249 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.Interop; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xunit; +using static Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer; + +using VerifyCS = LibraryImportGenerator.UnitTests.Verifiers.CSharpCodeFixVerifier< + Microsoft.Interop.Analyzers.CustomMarshallerAttributeAnalyzer, + Microsoft.Interop.Analyzers.CustomMarshallerAttributeFixer>; + +namespace LibraryImportGenerator.UnitTests +{ + [ActiveIssue("https://github.com/dotnet/runtime/issues/60650", TestRuntimes.Mono)] + public class CustomMarshallerAttributeAnalyzerTests_StatefulValueShapeValidation + { + [Fact] + public async Task ModeThatUsesManagedToUnmanagedShape_Missing_AllMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof({|#1:MarshallerType|}))] + struct MarshallerType + { + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromManagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromManagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToUnmanagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToUnmanagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(0).WithArguments("MarshallerType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(1).WithArguments("MarshallerType")); + } + + [Fact] + public async Task ModeThatUsesUnmanagedToManagedShape_Missing_AllMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof({|#0:MarshallerType|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedIn, typeof({|#1:MarshallerType|}))] + struct MarshallerType + { + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromUnmanagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromUnmanagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToManagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedOut, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToManagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedIn, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(0).WithArguments("MarshallerType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(1).WithArguments("MarshallerType")); + } + + [Fact] + public async Task Overloaded_FromUnmanaged_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedOut, typeof({|#0:MarshallerType|}))] + struct MarshallerType + { + public ManagedType ToManaged() => default; + public void FromUnmanaged(int i) {} + public void FromUnmanaged(float f) {} + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(FromUnmanagedOverloadsNotSupportedRule).WithLocation(0).WithArguments("MarshallerType")); + } + + [Fact] + public async Task ModeThatUsesBidirectionalShape_Missing_AllMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedRef, typeof({|#0:MarshallerType|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedRef, typeof({|#1:MarshallerType|}))] + struct MarshallerType + { + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(0).WithArguments("MarshallerType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromManagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromManagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToUnmanagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToUnmanagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromUnmanagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromUnmanagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToManagedRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ManagedToUnmanagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToManagedRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.UnmanagedToManagedRef, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(1).WithArguments("MarshallerType")); + } + + [Fact] + public async Task ModeThatUsesBidirectionalShape_MismatchedUnmanagedTypes_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedRef, typeof({|#0:MarshallerType|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedRef, typeof({|#1:MarshallerType|}))] + struct MarshallerType + { + public void FromManaged(ManagedType t) {} + public int ToUnmanaged() => default; + public void FromUnmanaged(float f) {} + public ManagedType ToManaged() => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(FirstParameterMustMatchReturnTypeRule).WithLocation(0).WithArguments("MarshallerType.FromUnmanaged(float)", "MarshallerType.ToUnmanaged()"), + VerifyCS.Diagnostic(FirstParameterMustMatchReturnTypeRule).WithLocation(1).WithArguments("MarshallerType.FromUnmanaged(float)", "MarshallerType.ToUnmanaged()")); + } + + [Fact] + public async Task ModeThatUsesBidirectionalShape_DoesNotReportDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedRef, typeof(MarshallerType))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedRef, typeof(MarshallerType))] + struct MarshallerType + { + public void FromManaged(ManagedType t) {} + public int ToUnmanaged() => default; + public void FromUnmanaged(int f) {} + public ManagedType ToManaged() => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source); + } + + [Fact] + public async Task ModeThatUsesElementMode_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ElementIn, typeof({|#0:MarshallerType|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.ElementRef, typeof({|#1:MarshallerType|}))] + [CustomMarshaller(typeof(ManagedType), MarshalMode.ElementOut, typeof({|#2:MarshallerType|}))] + struct MarshallerType + { + public void FromManaged(ManagedType t) {} + public int ToUnmanaged() => default; + public void FromUnmanaged(int f) {} + public ManagedType ToManaged() => default; + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(ElementMarshallerCannotBeStatefulRule).WithLocation(0).WithArguments("MarshallerType", MarshalMode.ElementIn), + VerifyCS.Diagnostic(ElementMarshallerCannotBeStatefulRule).WithLocation(1).WithArguments("MarshallerType", MarshalMode.ElementRef), + VerifyCS.Diagnostic(ElementMarshallerCannotBeStatefulRule).WithLocation(2).WithArguments("MarshallerType", MarshalMode.ElementOut)); + } + + [Fact] + public async Task DefaultMode_Missing_AllMethods_ReportsDiagnostic() + { + string source = """ + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.Default, typeof({|#0:MarshallerType|}))] + struct MarshallerType + { + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(StatefulMarshallerRequiresFreeRule).WithLocation(0).WithArguments("MarshallerType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromManagedRule).WithSeverity(DiagnosticSeverity.Info).WithLocation(0).WithArguments("MarshallerType", MarshalMode.Default, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToUnmanagedRule).WithSeverity(DiagnosticSeverity.Info).WithLocation(0).WithArguments("MarshallerType", MarshalMode.Default, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresFromUnmanagedRule).WithSeverity(DiagnosticSeverity.Info).WithLocation(0).WithArguments("MarshallerType", MarshalMode.Default, "ManagedType"), + VerifyCS.Diagnostic(StatefulMarshallerRequiresToManagedRule).WithSeverity(DiagnosticSeverity.Info).WithLocation(0).WithArguments("MarshallerType", MarshalMode.Default, "ManagedType")); + } + + [Fact] + public async Task CallerAllocatedBuffer_NoBufferSize_ReportsDiagnostic() + { + string source = """ + using System; + using System.Runtime.InteropServices.Marshalling; + + class ManagedType {} + + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType|}))] + struct MarshallerType + { + public void FromManaged(ManagedType m, Span b) {} + + public int ToUnmanaged() => default; + + public void Free() {} + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + source, + VerifyCS.Diagnostic(CallerAllocFromManagedMustHaveBufferSizeRule).WithLocation(0).WithArguments("MarshallerType", "byte")); + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessLinearCollectionShapeValidation.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessLinearCollectionShapeValidation.cs index bff15a1a125ba..5f1c0db2f4a28 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessLinearCollectionShapeValidation.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessLinearCollectionShapeValidation.cs @@ -665,7 +665,7 @@ public static int BufferSize await VerifyCS.VerifyCodeFixAsync( source, fixedSource, - VerifyCS.Diagnostic(StatelessLinearCollectionCallerAllocConstructorMustHaveBufferSizeRule).WithLocation(0).WithArguments("MarshallerType", "byte")); + VerifyCS.Diagnostic(StatelessLinearCollectionCallerAllocFromManagedMustHaveBufferSizeRule).WithLocation(0).WithArguments("MarshallerType", "byte")); } [Fact] diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessValueShapeValidation.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessValueShapeValidation.cs index dab3f86e3da84..dbfe4d8d2e9e9 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessValueShapeValidation.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CustomMarshallerAttributeFixerTests_StatelessValueShapeValidation.cs @@ -376,7 +376,7 @@ public static int BufferSize await VerifyCS.VerifyCodeFixAsync( source, fixedSource, - VerifyCS.Diagnostic(CallerAllocConstructorMustHaveBufferSizeRule).WithLocation(0).WithArguments("MarshallerType", "byte")); + VerifyCS.Diagnostic(CallerAllocFromManagedMustHaveBufferSizeRule).WithLocation(0).WithArguments("MarshallerType", "byte")); } [Fact] @@ -384,7 +384,7 @@ public async Task ModeThatUsesManagedToUnmanagedShape_Missing_ConvertToUnmanaged { string entryPointTypeSource = """ using System.Runtime.InteropServices.Marshalling; - + class ManagedType {} [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|SYSLIB1057:OtherMarshallerType|}))] @@ -427,9 +427,9 @@ public async Task ModeThatUsesManagedToUnmanagedShape_Missing_ConvertToUnmanaged { string entryPointTypeSource = """ using System.Runtime.InteropServices.Marshalling; - + class ManagedType {} - + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|SYSLIB1057:OtherMarshallerType|}))] [CustomMarshaller(typeof(ManagedType), MarshalMode.UnmanagedToManagedOut, typeof({|SYSLIB1057:OtherMarshallerType|}))] [CustomMarshaller(typeof(ManagedType), MarshalMode.ElementIn, typeof({|SYSLIB1057:OtherMarshallerType|}))] @@ -482,10 +482,10 @@ public async Task ModeThatUsesManagedToUnmanagedShape_Missing_ConvertToUnmanaged { string source = """ using System.Runtime.InteropServices.Marshalling; - + class ManagedType {} class ManagedType2 {} - + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof({|#0:MarshallerType|}))] [CustomMarshaller(typeof(ManagedType2), MarshalMode.ManagedToUnmanagedIn, typeof({|#1:MarshallerType|}))] static class MarshallerType @@ -495,10 +495,10 @@ static class MarshallerType string fixedSource = """ using System.Runtime.InteropServices.Marshalling; - + class ManagedType {} class ManagedType2 {} - + [CustomMarshaller(typeof(ManagedType), MarshalMode.ManagedToUnmanagedIn, typeof(MarshallerType))] [CustomMarshaller(typeof(ManagedType2), MarshalMode.ManagedToUnmanagedIn, typeof(MarshallerType))] static class MarshallerType