Share all "Compiles" tests from VTableIndexStubGenerator with ComInterfaceGenerator...
authorJackson Schuster <36744439+jtschuster@users.noreply.github.com>
Mon, 6 Mar 2023 19:46:13 +0000 (11:46 -0800)
committerGitHub <noreply@github.com>
Mon, 6 Mar 2023 19:46:13 +0000 (11:46 -0800)
Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>
12 files changed:
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatelessMarshallingStrategy.cs
src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs
src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs
src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratorKind.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IComInterfaceAttributeProvider.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IVirtualMethodIndexSignatureProvider.cs
src/libraries/System.Runtime.InteropServices/tests/Common/CustomCollectionMarshallingCodeSnippets.cs
src/libraries/System.Runtime.InteropServices/tests/Common/CustomStructMarshallingCodeSnippets.cs
src/libraries/System.Runtime.InteropServices/tests/Common/ICustomMarshallingSignatureTestProvider.cs
src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CodeSnippets.cs
src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CompileFails.cs
src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Compiles.cs

index 96cd0e1..e17f1c0 100644 (file)
@@ -92,7 +92,6 @@ namespace Microsoft.Interop
             {
                 var rewriter = new PointerNativeTypeAssignmentRewriter(assignment.Right.ToString(), (PointerTypeSyntax)pointer.Syntax);
                 assignment = (AssignmentExpressionSyntax)rewriter.Visit(assignment);
-
             }
             yield return ExpressionStatement(assignment);
         }
@@ -534,7 +533,7 @@ namespace Microsoft.Interop
             IMarshallingGenerator elementMarshaller,
             TypePositionInfo elementInfo,
             ExpressionSyntax numElementsExpression)
-            : base (unmanagedElementType, elementMarshaller, elementInfo)
+            : base(unmanagedElementType, elementMarshaller, elementInfo)
         {
             _marshallerTypeSyntax = marshallerTypeSyntax;
             _unmanagedType = unmanagedType;
index 9314731..561aaa1 100644 (file)
@@ -1,13 +1,54 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using Microsoft.Interop;
-using Microsoft.Interop.UnitTests;
+using System;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.Marshalling;
 
 namespace ComInterfaceGenerator.Unit.Tests
 {
-    internal partial class CodeSnippets
+    internal partial class CodeSnippets : IComInterfaceAttributeProvider
     {
+        private readonly GeneratorKind _generator;
+        GeneratorKind IComInterfaceAttributeProvider.Generator => _generator;
+
+        private string VirtualMethodIndex(
+            int index,
+            bool? ImplicitThisParameter = null,
+            MarshalDirection? Direction = null,
+            StringMarshalling? StringMarshalling = null,
+            Type? StringMarshallingCustomType = null,
+            bool? SetLastError = null,
+            ExceptionMarshalling? ExceptionMarshalling = null,
+            Type? ExceptionMarshallingType = null)
+            => ((IComInterfaceAttributeProvider)this).VirtualMethodIndex(
+                index,
+                ImplicitThisParameter,
+                Direction,
+                StringMarshalling,
+                StringMarshallingCustomType,
+                SetLastError,
+                ExceptionMarshalling,
+                ExceptionMarshallingType);
+
+        private string UnmanagedObjectUnwrapper(Type t) => ((IComInterfaceAttributeProvider)this).UnmanagedObjectUnwrapper(t);
+
+        private string GeneratedComInterface => ((IComInterfaceAttributeProvider)this).GeneratedComInterface;
+
+        public CodeSnippets(GeneratorKind generator)
+        {
+            this._generator = generator;
+        }
+
+        private string UnmanagedCallConv(Type[]? CallConvs = null)
+        {
+            var arguments = CallConvs?.Length is 0 or null ? "" : "(CallConvs = new[] {" + string.Join(", ", CallConvs!.Select(t => $"typeof({t.FullName})")) + "})";
+            return "[global::System.Runtime.InteropServices.UnmanagedCallConvAttribute"
+                + arguments + "]";
+        }
+
         public static readonly string DisableRuntimeMarshalling = "[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]";
         public static readonly string UsingSystemRuntimeInteropServicesMarshalling = "using System.Runtime.InteropServices.Marshalling;";
         public const string INativeAPI_IUnmanagedInterfaceTypeImpl = $$"""
@@ -29,59 +70,64 @@ sealed class NativeAPI : IUnmanagedVirtualMethodTableProvider, INativeAPI.Native
 }
 ";
 
-        public static readonly string SpecifiedMethodIndexNoExplicitParameters = @"
+        public string SpecifiedMethodIndexNoExplicitParameters => $@"
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
-{
-    [VirtualMethodIndex(0)]
+{{
+    {VirtualMethodIndex(0)}
     void Method();
-}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
+}}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        public static readonly string SpecifiedMethodIndexNoExplicitParametersNoImplicitThis = @"
+        public string SpecifiedMethodIndexNoExplicitParametersNoImplicitThis => $@"
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
-{
-    [VirtualMethodIndex(0, ImplicitThisParameter = false)]
+{{
+    {VirtualMethodIndex(0, ImplicitThisParameter: false)}
     void Method();
-}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        public static readonly string SpecifiedMethodIndexNoExplicitParametersCallConvWithCallingConventions = @"
+}}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
+
+        public string SpecifiedMethodIndexNoExplicitParametersCallConvWithCallingConventions => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
-{
+{{
 
-    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
-    [VirtualMethodIndex(0)]
+    {UnmanagedCallConv(CallConvs: new[] { typeof(CallConvCdecl) })}
+    {VirtualMethodIndex(0)}
     void Method();
-    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl), typeof(CallConvMemberFunction) })]
-    [VirtualMethodIndex(1)]
+    {UnmanagedCallConv(CallConvs: new[] { typeof(CallConvCdecl), typeof(CallConvMemberFunction) })}
+    {VirtualMethodIndex(1)}
     void Method1();
 
     [SuppressGCTransition]
-    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl), typeof(CallConvMemberFunction) })]
-    [VirtualMethodIndex(2)]
+    {UnmanagedCallConv(CallConvs: new[] { typeof(CallConvCdecl), typeof(CallConvMemberFunction) })}
+    {VirtualMethodIndex(2)}
     void Method2();
 
     [SuppressGCTransition]
-    [UnmanagedCallConv]
-    [VirtualMethodIndex(3)]
+    {UnmanagedCallConv()}
+    {VirtualMethodIndex(3)}
     void Method3();
 
     [SuppressGCTransition]
-    [VirtualMethodIndex(4)]
+    {VirtualMethodIndex(4)}
     void Method4();
-}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        public static string BasicParametersAndModifiers(string typeName, string preDeclaration = "") => $@"
+}}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
+
+        public string BasicParametersAndModifiers(string typeName, string preDeclaration = "") => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -89,13 +135,15 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0)]
+    {VirtualMethodIndex(0)}
     {typeName} Method({typeName} value, in {typeName} inValue, ref {typeName} refValue, out {typeName} outValue);
 }}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        public static string BasicParametersAndModifiersManagedToUnmanaged(string typeName, string preDeclaration = "") => $@"
+
+        public string BasicParametersAndModifiersManagedToUnmanaged(string typeName, string preDeclaration = "") => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -103,14 +151,15 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, Direction = MarshalDirection.ManagedToUnmanaged)]
+    {VirtualMethodIndex(0, Direction: MarshalDirection.ManagedToUnmanaged)}
     {typeName} Method({typeName} value, in {typeName} inValue, ref {typeName} refValue, out {typeName} outValue);
 }}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        public static string BasicParametersAndModifiers<T>() => BasicParametersAndModifiers(typeof(T).FullName!);
-        public static string BasicParametersAndModifiersNoRef(string typeName, string preDeclaration = "") => $@"
+        public string BasicParametersAndModifiers<T>() => BasicParametersAndModifiers(typeof(T).FullName!);
+        public string BasicParametersAndModifiersNoRef(string typeName, string preDeclaration = "") => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -118,36 +167,40 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0)]
+    {VirtualMethodIndex(0)}
     {typeName} Method({typeName} value, in {typeName} inValue, out {typeName} outValue);
 }}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        public static string BasicParametersAndModifiersNoImplicitThis(string typeName) => $@"
+
+        public string BasicParametersAndModifiersNoImplicitThis(string typeName) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = false)]
+    {VirtualMethodIndex(0, ImplicitThisParameter: false)}
     {typeName} Method({typeName} value, in {typeName} inValue, ref {typeName} refValue, out {typeName} outValue);
 }}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        public static string BasicParametersAndModifiersNoImplicitThis<T>() => BasicParametersAndModifiersNoImplicitThis(typeof(T).FullName!);
-        public static string MarshalUsingCollectionCountInfoParametersAndModifiers<T>() => MarshalUsingCollectionCountInfoParametersAndModifiers(typeof(T).ToString());
-        public static string MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType) => $@"
+        public string BasicParametersAndModifiersNoImplicitThis<T>() => BasicParametersAndModifiersNoImplicitThis(typeof(T).FullName!);
+        public string MarshalUsingCollectionCountInfoParametersAndModifiers<T>() => MarshalUsingCollectionCountInfoParametersAndModifiers(typeof(T).ToString());
+        public string MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0)]
+    {VirtualMethodIndex(0)}
     [return:MarshalUsing(ConstantElementCount=10)]
     {collectionType} Method(
         {collectionType} p,
@@ -158,38 +211,43 @@ partial interface INativeAPI : IUnmanagedInterfaceType
         out int pOutSize);
 }}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        public static string BasicReturnTypeComExceptionHandling(string typeName, string preDeclaration = "") => $@"
+        public string BasicReturnTypeComExceptionHandling(string typeName, string preDeclaration = "") => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 {preDeclaration}
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ExceptionMarshalling = ExceptionMarshalling.Com)]
+    {VirtualMethodIndex(0, ExceptionMarshalling : ExceptionMarshalling.Com)}
     {typeName} Method();
 }}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        public static string BasicReturnTypeCustomExceptionHandling(string typeName, string customExceptionType, string preDeclaration = "") => $@"
+        public string BasicReturnTypeCustomExceptionHandling(string typeName, string customExceptionType, string preDeclaration = "") => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 {preDeclaration}
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, CustomExceptionMarshallingType = typeof({customExceptionType}))]
+    {VirtualMethodIndex(0, ExceptionMarshallingType : Type.GetType(customExceptionType))}
     {typeName} Method();
 }}" + NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
         public class ManagedToUnmanaged : IVirtualMethodIndexSignatureProvider<ManagedToUnmanaged>
         {
+            public ManagedToUnmanaged(GeneratorKind generator) => Generator = generator;
             public static MarshalDirection Direction => MarshalDirection.ManagedToUnmanaged;
 
             public static bool ImplicitThisParameter => true;
 
+            public GeneratorKind Generator { get; }
+
             public static string NativeInterfaceUsage() => CodeSnippets.NativeInterfaceUsage();
         }
         public class ManagedToUnmanagedNoImplicitThis : IVirtualMethodIndexSignatureProvider<ManagedToUnmanagedNoImplicitThis>
@@ -198,6 +256,10 @@ partial interface INativeAPI : IUnmanagedInterfaceType
 
             public static bool ImplicitThisParameter => false;
 
+            public GeneratorKind Generator { get; }
+
+            public ManagedToUnmanagedNoImplicitThis(GeneratorKind generator) => Generator = generator;
+
             public static string NativeInterfaceUsage() => CodeSnippets.NativeInterfaceUsage();
         }
         public class UnmanagedToManaged : IVirtualMethodIndexSignatureProvider<UnmanagedToManaged>
@@ -206,6 +268,10 @@ partial interface INativeAPI : IUnmanagedInterfaceType
 
             public static bool ImplicitThisParameter => true;
 
+            public GeneratorKind Generator { get; }
+
+            public UnmanagedToManaged(GeneratorKind generator) => Generator = generator;
+
             // Unmanaged-to-managed-only stubs don't provide implementations for the interface, so we don't want to try to use the generated nested interface
             // since it won't have managed implementations for the methods
             public static string NativeInterfaceUsage() => string.Empty;
@@ -215,6 +281,11 @@ partial interface INativeAPI : IUnmanagedInterfaceType
             public static MarshalDirection Direction => MarshalDirection.Bidirectional;
 
             public static bool ImplicitThisParameter => true;
+
+            public GeneratorKind Generator { get; }
+
+            public Bidirectional(GeneratorKind generator) => Generator = generator;
+
             public static string NativeInterfaceUsage() => CodeSnippets.NativeInterfaceUsage();
         }
     }
index 234feaa..7736c41 100644 (file)
@@ -3,6 +3,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Runtime.CompilerServices;
 using System.Threading.Tasks;
 using Microsoft.CodeAnalysis;
@@ -18,275 +19,283 @@ namespace ComInterfaceGenerator.Unit.Tests
             [CallerFilePath] string? filePath = null)
             => TestUtils.GetFileLineName(lineNumber, filePath);
 
-        public static IEnumerable<object[]> CodeSnippetsToCompile()
+        public static IEnumerable<object[]> CodeSnippetsToCompile(GeneratorKind generator)
         {
-            yield return new[] { ID(), CodeSnippets.SpecifiedMethodIndexNoExplicitParameters };
-            yield return new[] { ID(), CodeSnippets.SpecifiedMethodIndexNoExplicitParametersNoImplicitThis };
-            yield return new[] { ID(), CodeSnippets.SpecifiedMethodIndexNoExplicitParametersCallConvWithCallingConventions };
+            CodeSnippets codeSnippets = new(generator);
+            yield return new[] { ID(), codeSnippets.SpecifiedMethodIndexNoExplicitParameters };
+            yield return new[] { ID(), codeSnippets.SpecifiedMethodIndexNoExplicitParametersNoImplicitThis };
+            yield return new[] { ID(), codeSnippets.SpecifiedMethodIndexNoExplicitParametersCallConvWithCallingConventions };
 
             // Basic marshalling validation
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<short>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<int>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<long>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<float>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<double>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<byte>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<sbyte>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<short>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<ushort>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<int>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<uint>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<long>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<ulong>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<float>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<double>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<IntPtr>() };
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersNoImplicitThis<UIntPtr>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<byte>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<short>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<int>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<uint>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<long>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<float>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<double>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<byte>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<sbyte>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<short>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<ushort>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<int>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<uint>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<long>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<ulong>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<float>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<double>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<IntPtr>() };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersNoImplicitThis<UIntPtr>() };
 
             // Custom type marshalling managed-to-unmanaged
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NativeToManagedFinallyOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NativeToManagedFinallyOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.PinByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.StackallocByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.StackallocParametersAndModifiersNoRef };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.OptionalStackallocParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.DefaultModeByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.DefaultModeReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ParametersAndModifiersWithFree };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ParametersAndModifiersWithOnInvoked };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NativeToManagedFinallyOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NativeToManagedFinallyOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.StackallocByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.PinByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.MarshallerPinByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.StackallocParametersAndModifiersNoRef };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.OptionalStackallocParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.DefaultModeByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.DefaultModeReturnValue };
+            CustomStructMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged> customStructMarshallingCodeSnippetsManagedToUnmanaged = new(new(generator));
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NativeToManagedFinallyOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NativeToManagedOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NativeToManagedFinallyOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.PinByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.StackallocByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.StackallocParametersAndModifiersNoRef };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.OptionalStackallocParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.DefaultModeByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateless.DefaultModeReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ParametersAndModifiersWithFree };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ParametersAndModifiersWithOnInvoked };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NativeToManagedFinallyOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NativeToManagedOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NativeToManagedFinallyOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.StackallocByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.PinByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.MarshallerPinByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.StackallocParametersAndModifiersNoRef };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.OptionalStackallocParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.DefaultModeByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsManagedToUnmanaged.Stateful.DefaultModeReturnValue };
 
             // Custom type marshalling unmanaged-to-managed
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateless.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateless.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateless.NativeToManagedOnlyInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateless.NativeToManagedFinallyOnlyInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateless.ByValueOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateless.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateless.OptionalStackallocParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.ParametersAndModifiersWithFree };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.ParametersAndModifiersWithOnInvoked };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.NativeToManagedOnlyInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.NativeToManagedFinallyOnlyInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.ByValueOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged>.Stateful.OptionalStackallocParametersAndModifiers };
+            CustomStructMarshallingCodeSnippets<CodeSnippets.UnmanagedToManaged> customStructMarshallingCodeSnippetsUnmanagedToManaged = new(new(generator));
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateless.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateless.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateless.NativeToManagedOnlyInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateless.NativeToManagedFinallyOnlyInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateless.ByValueOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateless.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateless.OptionalStackallocParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.ParametersAndModifiersWithFree };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.ParametersAndModifiersWithOnInvoked };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.NativeToManagedOnlyInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.NativeToManagedFinallyOnlyInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.ByValueOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsUnmanagedToManaged.Stateful.OptionalStackallocParametersAndModifiers };
 
             // Custom type marshalling bidirectional
-
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.OptionalStackallocParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.ParametersAndModifiersWithFree };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.ParametersAndModifiersWithOnInvoked };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.OptionalStackallocParametersAndModifiers };
+            CustomStructMarshallingCodeSnippets<CodeSnippets.Bidirectional> customStructMarshallingCodeSnippetsBidirectional = new(new(generator));
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateless.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateless.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateless.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateless.OptionalStackallocParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateful.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateful.ParametersAndModifiersWithFree };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateful.ParametersAndModifiersWithOnInvoked };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateful.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateful.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippetsBidirectional.Stateful.OptionalStackallocParametersAndModifiers };
 
             // SafeHandles
-            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiersManagedToUnmanaged("Microsoft.Win32.SafeHandles.SafeFileHandle") };
+            yield return new[] { ID(), codeSnippets.BasicParametersAndModifiersManagedToUnmanaged("Microsoft.Win32.SafeHandles.SafeFileHandle") };
 
             // Exception Handling
             // HResult
-            yield return new[] { ID(), CodeSnippets.BasicReturnTypeComExceptionHandling("int") };
-            yield return new[] { ID(), CodeSnippets.BasicReturnTypeComExceptionHandling("uint") };
+            yield return new[] { ID(), codeSnippets.BasicReturnTypeComExceptionHandling("int") };
+            yield return new[] { ID(), codeSnippets.BasicReturnTypeComExceptionHandling("uint") };
             // NaN
-            yield return new[] { ID(), CodeSnippets.BasicReturnTypeComExceptionHandling("float") };
-            yield return new[] { ID(), CodeSnippets.BasicReturnTypeComExceptionHandling("double") };
+            yield return new[] { ID(), codeSnippets.BasicReturnTypeComExceptionHandling("float") };
+            yield return new[] { ID(), codeSnippets.BasicReturnTypeComExceptionHandling("double") };
             // Default Value
-            yield return new[] { ID(), CodeSnippets.BasicReturnTypeComExceptionHandling("nint") };
+            yield return new[] { ID(), codeSnippets.BasicReturnTypeComExceptionHandling("nint") };
             // Void
-            yield return new[] { ID(), CodeSnippets.BasicReturnTypeComExceptionHandling("void") }; 
+            yield return new[] { ID(), codeSnippets.BasicReturnTypeComExceptionHandling("void") };
         }
 
-        public static IEnumerable<object[]> CustomCollections()
+        public static IEnumerable<object[]> CustomCollections(GeneratorKind generator)
         {
             // Custom collection marshalling
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValue<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.ByValueWithPinning<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValue<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueCallerAllocatedBuffer<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithPinning<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.ByValueWithStaticPinning<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NativeToManagedOnlyOutParameter<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NativeToManagedOnlyReturnValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NonBlittableElementByValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NonBlittableElementNativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateless.NonBlittableElementNativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NativeToManagedOnlyOutParameter<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NativeToManagedOnlyReturnValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NonBlittableElementByValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NonBlittableElementNativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged>.Stateful.NonBlittableElementNativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<byte[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<sbyte[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<short[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<ushort[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<int[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<uint[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<long[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<ulong[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<float[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<double[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<IntPtr[]>() };
-            yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<UIntPtr[]>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomMarshallerReturnValueLength<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.NestedMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.NonBlittableElementParametersAndModifiers };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateless.CustomElementMarshalling };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomMarshallerReturnValueLength<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.NonBlittableElementParametersAndModifiers };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional>.Stateful.CustomElementMarshalling };
+            CustomCollectionMarshallingCodeSnippets<CodeSnippets.ManagedToUnmanaged> customCollectionMarshallingCodeSnippetsManagedToUnmanaged = new(new(generator));
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValue<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.ByValueWithPinning<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValue<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueCallerAllocatedBuffer<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithPinning<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.ByValueWithStaticPinning<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NativeToManagedOnlyOutParameter<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NativeToManagedOnlyReturnValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NonBlittableElementByValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NonBlittableElementNativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateless.NonBlittableElementNativeToManagedOnlyReturnValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NativeToManagedOnlyOutParameter<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NativeToManagedOnlyReturnValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NonBlittableElementByValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NonBlittableElementNativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsManagedToUnmanaged.Stateful.NonBlittableElementNativeToManagedOnlyReturnValue };
+
+            CodeSnippets codeSnippets = new(generator);
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<byte[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<sbyte[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<short[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<ushort[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<int[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<uint[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<long[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<ulong[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<float[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<double[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<IntPtr[]>() };
+            yield return new[] { ID(), codeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<UIntPtr[]>() };
+
+            CustomCollectionMarshallingCodeSnippets<CodeSnippets.Bidirectional> customCollectionMarshallingCodeSnippetsBidirectional = new(new(generator));
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomMarshallerReturnValueLength<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.NestedMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.NonBlittableElementParametersAndModifiers };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateless.CustomElementMarshalling };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomMarshallerReturnValueLength<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.NonBlittableElementParametersAndModifiers };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippetsBidirectional.Stateful.CustomElementMarshalling };
         }
 
         [Theory]
-        [MemberData(nameof(CodeSnippetsToCompile))]
-        [MemberData(nameof(CustomCollections))]
+        [MemberData(nameof(CodeSnippetsToCompile), GeneratorKind.VTableIndexStubGenerator)]
+        [MemberData(nameof(CustomCollections), GeneratorKind.VTableIndexStubGenerator)]
         public async Task ValidateVTableIndexSnippets(string id, string source)
         {
             _ = id;
@@ -300,5 +309,57 @@ namespace ComInterfaceGenerator.Unit.Tests
 
             TestUtils.AssertPostSourceGeneratorCompilation(newComp, "CS0105");
         }
+
+        [Theory]
+        [MemberData(nameof(CodeSnippetsToCompile), GeneratorKind.ComInterfaceGenerator)]
+        [MemberData(nameof(CustomCollections), GeneratorKind.ComInterfaceGenerator)]
+        public async Task ValidateComInterfaceSnippets(string id, string source)
+        {
+            _ = id;
+            Compilation comp = await TestUtils.CreateCompilation(source);
+            // Allow the Native nested type name to be missing in the pre-source-generator compilation
+            // We allow duplicate usings here since some of the shared snippets add a using for System.Runtime.InteropServices.Marshalling when we already have one in our base snippets.
+            TestUtils.AssertPreSourceGeneratorCompilation(comp, "CS0426", "CS0105");
+
+            var newComp = TestUtils.RunGenerators(comp, out var generatorDiags, new Microsoft.Interop.ComInterfaceGenerator());
+            Assert.Empty(generatorDiags.Where(IsValidGeneratorDiagnostic));
+
+            List<string> allowedDiagnostics = new()
+            {
+                // Duplicate 'using'
+                "CS0105",
+                // ComWrappersUnwrapper is inaccessible due to its protection level
+                "CS0122",
+                // Variable assigned to but never read
+                "CS0219"
+            };
+            // There are valid warnings from the generator -- 
+            if (generatorDiags.Length != 0)
+            {
+                List<string> additionalDiags = new() {
+                    // No overload for 'ABI_Method' matches function pointer 'delegate* unmanaged<...>'
+                    "CS8757",
+                    // Cannot use 'parameterType' as a parameter type on a method attributed with 'UnmanagedCallersOnly'.
+                    "CS8894",
+                    // The out parameter 'paramName' must be assigned to before control leaves the current method
+                    "CS0177",
+                    // Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'.
+                    "CS8977",
+                    // The type 'SafeFileHandle' must be a non-nullable value type, along with all fields at any level of nesting,
+                    // in order to use it as parameter 'T' in the generic type or method 'ExceptionDefaultMarshaller<T>'
+                    "CS8377",
+                    // Argument N may not be passed with the 'in' keyword
+                    "CS1615"
+                };
+                allowedDiagnostics.AddRange(additionalDiags);
+            }
+
+            TestUtils.AssertPostSourceGeneratorCompilation(newComp, allowedDiagnostics.ToArray());
+        }
+
+        private bool IsValidGeneratorDiagnostic(Diagnostic diag)
+            => diag.Id != "SYSLIB1051"
+                && diag.GetMessage().Contains("The specified parameter needs to be marshalled from managed to unmanaged, but the marshaller type '")
+                && diag.GetMessage().Contains("' does not support it. The generated source will not handle marshalling of parameter");
     }
 }
diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratorKind.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratorKind.cs
new file mode 100644 (file)
index 0000000..f450942
--- /dev/null
@@ -0,0 +1,11 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace ComInterfaceGenerator.Unit.Tests
+{
+    public enum GeneratorKind
+    {
+        ComInterfaceGenerator,
+        VTableIndexStubGenerator
+    }
+}
diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IComInterfaceAttributeProvider.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/IComInterfaceAttributeProvider.cs
new file mode 100644 (file)
index 0000000..cf8ef6f
--- /dev/null
@@ -0,0 +1,66 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.Marshalling;
+
+namespace ComInterfaceGenerator.Unit.Tests
+{
+    /// <summary>
+    /// Provides methods for adding attributes in a snippet if the generator requires them, or leaving them out if the generator doesn't require them.
+    /// </summary>
+    internal interface IComInterfaceAttributeProvider
+    {
+        public GeneratorKind Generator { get; }
+
+        /// <summary>
+        /// Returns the [VirtualMethodIndexAttribute] to be put into a snippet if Generator is <see cref="GeneratorKind.VTableIndexStubGenerator"/>, or an empty string if Generator is <see cref="GeneratorKind.ComInterfaceGenerator"/>.
+        /// </summary>
+        public string VirtualMethodIndex(
+            int index,
+            bool? ImplicitThisParameter = null,
+            MarshalDirection? Direction = null,
+            StringMarshalling? StringMarshalling = null,
+            Type? StringMarshallingCustomType = null,
+            bool? SetLastError = null,
+            ExceptionMarshalling? ExceptionMarshalling = null,
+            Type? ExceptionMarshallingType = null)
+                => Generator switch
+                {
+                    GeneratorKind.ComInterfaceGenerator => "",
+                    GeneratorKind.VTableIndexStubGenerator =>
+                        "[global::System.Runtime.InteropServices.Marshalling.VirtualMethodIndexAttribute("
+                        + index.ToString()
+                        + (ImplicitThisParameter.HasValue ? $", ImplicitThisParameter = {ImplicitThisParameter.Value.ToString().ToLower()}" : "")
+                        + (Direction is not null ? $", Direction = {typeof(MarshalDirection).FullName}.{Direction.Value}" : "")
+                        + (StringMarshalling is not null ? $", StringMarshalling = {typeof(StringMarshalling).FullName}.{StringMarshalling!.Value}" : "")
+                        + (StringMarshallingCustomType is not null ? $", StringMarshallingCustomType = {StringMarshallingCustomType!.FullName}" : "")
+                        + (SetLastError is not null ? $", SetLastError = {SetLastError.Value.ToString().ToLower()}" : "")
+                        + (ExceptionMarshalling is not null ? $", ExceptionMarshalling = {typeof(ExceptionMarshalling).FullName}.{ExceptionMarshalling.Value}" : "")
+                        + (ExceptionMarshallingType is not null ? $", ExceptionMarshallingCustomType = {ExceptionMarshallingType!.FullName}" : "")
+                        + ")]",
+                    _ => throw new NotImplementedException()
+                };
+
+        /// <summary>
+        /// Returns the [UnmanagedObjectUnwrapper] to be put into a snippet if Generator is <see cref="GeneratorKind.VTableIndexStubGenerator"/>, or an empty string if Generator is <see cref="GeneratorKind.ComInterfaceGenerator"/>.
+        /// </summary>
+        public string UnmanagedObjectUnwrapper(Type t) => Generator switch
+        {
+            GeneratorKind.VTableIndexStubGenerator => $"[global::System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapperAttribute<{t.FullName!.Replace('+', '.')}>]",
+            GeneratorKind.ComInterfaceGenerator => "",
+            _ => throw new NotImplementedException(),
+        };
+
+        /// <summary>
+        /// Returns the [ComInterfaceTypeAttribute] to be put into a snippet if Generator is <see cref="GeneratorKind.ComInterfaceGenerator"/>, or an empty string if Generator is <see cref="GeneratorKind.VTableIndexStubGenerator"/>.
+        /// </summary>
+        public string GeneratedComInterface => Generator switch
+        {
+            GeneratorKind.VTableIndexStubGenerator => "",
+            GeneratorKind.ComInterfaceGenerator => $"[global::System.Runtime.InteropServices.Marshalling.GeneratedComInterfaceAttribute]",
+            _ => throw new NotImplementedException(),
+        };
+    }
+}
index dc683b4..bf5bfd3 100644 (file)
@@ -6,12 +6,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using Microsoft.Interop;
+using System.Runtime.InteropServices.Marshalling;
 using Microsoft.Interop.UnitTests;
 
 namespace ComInterfaceGenerator.Unit.Tests
 {
-    internal interface IVirtualMethodIndexSignatureProvider<TProvider> : ICustomMarshallingSignatureTestProvider
+    internal interface IVirtualMethodIndexSignatureProvider<TProvider> : ICustomMarshallingSignatureTestProvider, IComInterfaceAttributeProvider
         where TProvider : IVirtualMethodIndexSignatureProvider<TProvider>
     {
         public static abstract MarshalDirection Direction { get; }
@@ -31,7 +31,7 @@ namespace ComInterfaceGenerator.Unit.Tests
             """;
 
         public static abstract string NativeInterfaceUsage();
-        static string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiers(string typeName, string preDeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiers(string typeName, string preDeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -39,13 +39,14 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     {typeName} Method({typeName} value, in {typeName} inValue, ref {typeName} refValue, out {typeName} outValue);
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiersNoRef(string typeName, string preDeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiersNoRef(string typeName, string preDeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -53,27 +54,29 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     {typeName} Method({typeName} value, in {typeName} inValue, out {typeName} outValue);
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        static string ICustomMarshallingSignatureTestProvider.BasicParameterByValue(string typeName, string preDeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.BasicParameterByValue(string typeName, string preDeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 {preDeclaration}
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     void Method({typeName} value);
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        static string ICustomMarshallingSignatureTestProvider.BasicParameterWithByRefModifier(string modifier, string typeName, string preDeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.BasicParameterWithByRefModifier(string modifier, string typeName, string preDeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -81,34 +84,37 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     void Method({modifier} {typeName} value);
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.BasicReturnType(string typeName, string preDeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.BasicReturnType(string typeName, string preDeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 {preDeclaration}
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     {typeName} Method();
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.MarshalUsingParametersAndModifiers(string typeName, string marshallerTypeName, string preDeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingParametersAndModifiers(string typeName, string marshallerTypeName, string preDeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 {preDeclaration}
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     [return: MarshalUsing(typeof({marshallerTypeName}))]
     {typeName} Method(
         [MarshalUsing(typeof({marshallerTypeName}))] {typeName} p,
@@ -116,16 +122,17 @@ partial interface INativeAPI : IUnmanagedInterfaceType
         [MarshalUsing(typeof({marshallerTypeName}))] ref {typeName} pRef,
         [MarshalUsing(typeof({marshallerTypeName}))] out {typeName} pOut);
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType) => $@"
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     [return:MarshalUsing(ConstantElementCount=10)]
     {collectionType} Method(
         {collectionType} p,
@@ -135,17 +142,18 @@ partial interface INativeAPI : IUnmanagedInterfaceType
         [MarshalUsing(CountElementName = ""pOutSize"")] out {collectionType} pOut,
         out int pOutSize);
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionParametersAndModifiers(string collectionType, string marshallerType) => $@"
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionParametersAndModifiers(string collectionType, string marshallerType) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     [return:MarshalUsing(typeof({marshallerType}), ConstantElementCount=10)]
     {collectionType} Method(
         [MarshalUsing(typeof({marshallerType}))] {collectionType} p,
@@ -156,23 +164,24 @@ partial interface INativeAPI : IUnmanagedInterfaceType
         out int pOutSize
         );
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnValueLength(string collectionType, string marshallerType) => $@"
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnValueLength(string collectionType, string marshallerType) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     int Method(
         [MarshalUsing(typeof({marshallerType}), CountElementName = MarshalUsingAttribute.ReturnsCountValue)] out {collectionType} pOut
         );
 }}" + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
 
-        static string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionOutConstantLength(string collectionType, string predeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionOutConstantLength(string collectionType, string predeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -180,16 +189,17 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     int Method(
         [MarshalUsing(ConstantElementCount = 10)] out {collectionType} pOut
         );
 }}
 " + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnConstantLength(string collectionType, string predeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnConstantLength(string collectionType, string predeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -197,15 +207,16 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     [return:MarshalUsing(ConstantElementCount = 10)]
     {collectionType} Method();
 }}
 " + TProvider.NativeInterfaceUsage() + INativeAPI_IUnmanagedInterfaceTypeImpl;
-        static string ICustomMarshallingSignatureTestProvider.CustomElementMarshalling(string collectionType, string elementMarshaller, string predeclaration) => $@"
+        string ICustomMarshallingSignatureTestProvider.CustomElementMarshalling(string collectionType, string elementMarshaller, string predeclaration) => $@"
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.Marshalling;
@@ -213,10 +224,11 @@ using System.Runtime.InteropServices.Marshalling;
 
 [assembly:DisableRuntimeMarshalling]
 
-[UnmanagedObjectUnwrapper<UnmanagedObjectUnwrapper.TestUnwrapper>]
+{UnmanagedObjectUnwrapper(typeof(UnmanagedObjectUnwrapper.TestUnwrapper))}
+{GeneratedComInterface}
 partial interface INativeAPI : IUnmanagedInterfaceType
 {{
-    [VirtualMethodIndex(0, ImplicitThisParameter = {TProvider.ImplicitThisParameter.ToString().ToLowerInvariant()}, Direction = MarshalDirection.{TProvider.Direction})]
+    {VirtualMethodIndex(0, ImplicitThisParameter: TProvider.ImplicitThisParameter, Direction: TProvider.Direction)}
     [return:MarshalUsing(ConstantElementCount=10)]
     [return:MarshalUsing(typeof({elementMarshaller}), ElementIndirectionDepth = 1)]
     TestCollection<int> Method(
index e5a92ce..6525d21 100644 (file)
@@ -3,9 +3,19 @@
 
 namespace Microsoft.Interop.UnitTests
 {
-    public static class CustomCollectionMarshallingCodeSnippets<TSignatureTestProvider>
+    public class CustomCollectionMarshallingCodeSnippets<TSignatureTestProvider>
         where TSignatureTestProvider : ICustomMarshallingSignatureTestProvider
     {
+        TSignatureTestProvider _provider;
+        public StatelessSnippets Stateless { get; }
+        public StatefulSnippets Stateful { get; }
+        public CustomCollectionMarshallingCodeSnippets(TSignatureTestProvider provider)
+        {
+            _provider = provider;
+            Stateless = new StatelessSnippets(this, provider);
+            Stateful = new StatefulSnippets(this, provider);
+        }
+
         public static readonly string DisableRuntimeMarshalling = "[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]";
         public static readonly string UsingSystemRuntimeInteropServicesMarshalling = "using System.Runtime.InteropServices.Marshalling;";
 
@@ -14,8 +24,8 @@ namespace Microsoft.Interop.UnitTests
 class TestCollection<T> {{}}
 ";
 
-        public static string CollectionOutParameter(string collectionType, string predeclaration = "") => TSignatureTestProvider.MarshalUsingCollectionOutConstantLength(collectionType, predeclaration);
-        public static string CollectionReturnType(string collectionType, string predeclaration = "") => TSignatureTestProvider.MarshalUsingCollectionReturnConstantLength(collectionType, predeclaration);
+        public string CollectionOutParameter(string collectionType, string predeclaration = "") => _provider.MarshalUsingCollectionOutConstantLength(collectionType, predeclaration);
+        public string CollectionReturnType(string collectionType, string predeclaration = "") => _provider.MarshalUsingCollectionReturnConstantLength(collectionType, predeclaration);
         public const string NonBlittableElement = @"
 [NativeMarshalling(typeof(ElementMarshaller))]
 struct Element
@@ -65,8 +75,16 @@ static class CustomIntMarshaller
     public static int ConvertToManaged(Native n) => throw null;
 }
 ";
-        public static class Stateless
+        public class StatelessSnippets
         {
+            TSignatureTestProvider _provider;
+            CustomCollectionMarshallingCodeSnippets<TSignatureTestProvider> _snippets;
+            public StatelessSnippets(CustomCollectionMarshallingCodeSnippets<TSignatureTestProvider> instance, TSignatureTestProvider provider)
+            {
+                _provider = provider;
+                _snippets = instance;
+            }
+
             public const string In = @"
 [CustomMarshaller(typeof(TestCollection<>), MarshalMode.ManagedToUnmanagedIn, typeof(Marshaller<,>))]
 [ContiguousCollectionMarshaller]
@@ -174,92 +192,92 @@ static unsafe class Marshaller<T, TUnmanagedElement> where TUnmanagedElement : u
     public static System.ReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(byte* unmanaged, int numElements) => throw null;
 }
 ";
-            public static string ByValue<T>() => ByValue(typeof(T).ToString());
-            public static string ByValue(string elementType) => TSignatureTestProvider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
+            public string ByValue<T>() => ByValue(typeof(T).ToString());
+            public string ByValue(string elementType) => _provider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + In;
 
-            public static string ByValueWithPinning<T>() => ByValueWithPinning(typeof(T).ToString());
-            public static string ByValueWithPinning(string elementType) => TSignatureTestProvider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
+            public string ByValueWithPinning<T>() => ByValueWithPinning(typeof(T).ToString());
+            public string ByValueWithPinning(string elementType) => _provider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + InPinnable;
 
-            public static string ByValueCallerAllocatedBuffer<T>() => ByValueCallerAllocatedBuffer(typeof(T).ToString());
-            public static string ByValueCallerAllocatedBuffer(string elementType) => TSignatureTestProvider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
+            public string ByValueCallerAllocatedBuffer<T>() => ByValueCallerAllocatedBuffer(typeof(T).ToString());
+            public string ByValueCallerAllocatedBuffer(string elementType) => _provider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + InBuffer;
 
-            public static string DefaultMarshallerParametersAndModifiers<T>() => DefaultMarshallerParametersAndModifiers(typeof(T).ToString());
-            public static string DefaultMarshallerParametersAndModifiers(string elementType) => TSignatureTestProvider.MarshalUsingCollectionCountInfoParametersAndModifiers($"TestCollection<{elementType}>")
+            public string DefaultMarshallerParametersAndModifiers<T>() => DefaultMarshallerParametersAndModifiers(typeof(T).ToString());
+            public string DefaultMarshallerParametersAndModifiers(string elementType) => _provider.MarshalUsingCollectionCountInfoParametersAndModifiers($"TestCollection<{elementType}>")
                 + TestCollection()
                 + Default;
 
-            public static string CustomMarshallerParametersAndModifiers<T>() => CustomMarshallerParametersAndModifiers(typeof(T).ToString());
-            public static string CustomMarshallerParametersAndModifiers(string elementType) => TSignatureTestProvider.MarshalUsingCollectionParametersAndModifiers($"TestCollection<{elementType}>", $"Marshaller<,>")
+            public string CustomMarshallerParametersAndModifiers<T>() => CustomMarshallerParametersAndModifiers(typeof(T).ToString());
+            public string CustomMarshallerParametersAndModifiers(string elementType) => _provider.MarshalUsingCollectionParametersAndModifiers($"TestCollection<{elementType}>", $"Marshaller<,>")
                 + TestCollection(defineNativeMarshalling: false)
                 + Default;
 
-            public static string CustomMarshallerReturnValueLength<T>() => CustomMarshallerReturnValueLength(typeof(T).ToString());
-            public static string CustomMarshallerReturnValueLength(string elementType) => TSignatureTestProvider.MarshalUsingCollectionReturnValueLength($"TestCollection<{elementType}>", $"Marshaller<,>")
+            public string CustomMarshallerReturnValueLength<T>() => CustomMarshallerReturnValueLength(typeof(T).ToString());
+            public string CustomMarshallerReturnValueLength(string elementType) => _provider.MarshalUsingCollectionReturnValueLength($"TestCollection<{elementType}>", $"Marshaller<,>")
                 + TestCollection(defineNativeMarshalling: false)
                 + Default;
 
-            public static string NativeToManagedOnlyOutParameter<T>() => NativeToManagedOnlyOutParameter(typeof(T).ToString());
-            public static string NativeToManagedOnlyOutParameter(string elementType) => CollectionOutParameter($"TestCollection<{elementType}>")
+            public string NativeToManagedOnlyOutParameter<T>() => NativeToManagedOnlyOutParameter(typeof(T).ToString());
+            public string NativeToManagedOnlyOutParameter(string elementType) => _snippets.CollectionOutParameter($"TestCollection<{elementType}>")
                 + TestCollection()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyOutParameter<T>() => NativeToManagedFinallyOnlyOutParameter(typeof(T).ToString());
-            public static string NativeToManagedFinallyOnlyOutParameter(string elementType) => CollectionOutParameter($"TestCollection<{elementType}>")
+            public string NativeToManagedFinallyOnlyOutParameter<T>() => NativeToManagedFinallyOnlyOutParameter(typeof(T).ToString());
+            public string NativeToManagedFinallyOnlyOutParameter(string elementType) => _snippets.CollectionOutParameter($"TestCollection<{elementType}>")
                 + TestCollection()
                 + OutGuaranteed;
-            public static string NativeToManagedOnlyReturnValue<T>() => NativeToManagedOnlyReturnValue(typeof(T).ToString());
-            public static string NativeToManagedOnlyReturnValue(string elementType) => CollectionReturnType($"TestCollection<{elementType}>")
+            public string NativeToManagedOnlyReturnValue<T>() => NativeToManagedOnlyReturnValue(typeof(T).ToString());
+            public string NativeToManagedOnlyReturnValue(string elementType) => _snippets.CollectionReturnType($"TestCollection<{elementType}>")
                 + TestCollection()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyReturnValue<T>() => NativeToManagedFinallyOnlyReturnValue(typeof(T).ToString());
-            public static string NativeToManagedFinallyOnlyReturnValue(string elementType) => CollectionReturnType($"TestCollection<{elementType}>")
+            public string NativeToManagedFinallyOnlyReturnValue<T>() => NativeToManagedFinallyOnlyReturnValue(typeof(T).ToString());
+            public string NativeToManagedFinallyOnlyReturnValue(string elementType) => _snippets.CollectionReturnType($"TestCollection<{elementType}>")
                 + TestCollection()
                 + OutGuaranteed;
-            public static string NestedMarshallerParametersAndModifiers<T>() => NestedMarshallerParametersAndModifiers(typeof(T).ToString());
-            public static string NestedMarshallerParametersAndModifiers(string elementType) => TSignatureTestProvider.MarshalUsingCollectionCountInfoParametersAndModifiers($"TestCollection<{elementType}>")
+            public string NestedMarshallerParametersAndModifiers<T>() => NestedMarshallerParametersAndModifiers(typeof(T).ToString());
+            public string NestedMarshallerParametersAndModifiers(string elementType) => _provider.MarshalUsingCollectionCountInfoParametersAndModifiers($"TestCollection<{elementType}>")
                 + TestCollection()
                 + DefaultNested;
 
-            public static string NonBlittableElementParametersAndModifiers => DefaultMarshallerParametersAndModifiers("Element")
+            public string NonBlittableElementParametersAndModifiers => DefaultMarshallerParametersAndModifiers("Element")
                 + NonBlittableElement
                 + ElementMarshaller;
 
-            public static string NonBlittableElementByValue => ByValue("Element")
+            public string NonBlittableElementByValue => ByValue("Element")
                 + NonBlittableElement
                 + ElementIn;
 
-            public static string NonBlittableElementNativeToManagedOnlyOutParameter => NativeToManagedOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedOnlyOutParameter => NativeToManagedOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
 
-            public static string NonBlittableElementNativeToManagedFinallyOnlyOutParameter => NativeToManagedFinallyOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedFinallyOnlyOutParameter => NativeToManagedFinallyOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
 
-            public static string NonBlittableElementNativeToManagedOnlyReturnValue => NativeToManagedOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedOnlyReturnValue => NativeToManagedOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
 
-            public static string NonBlittableElementNativeToManagedFinallyOnlyReturnValue => NativeToManagedFinallyOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedFinallyOnlyReturnValue => NativeToManagedFinallyOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
 
-            public static string DefaultModeByValueInParameter => TSignatureTestProvider.BasicParameterByValue($"TestCollection<int>", DisableRuntimeMarshalling)
+            public string DefaultModeByValueInParameter => _provider.BasicParameterByValue($"TestCollection<int>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + DefaultIn;
 
-            public static string DefaultModeReturnValue => CollectionOutParameter($"TestCollection<int>")
+            public string DefaultModeReturnValue => _snippets.CollectionOutParameter($"TestCollection<int>")
                 + TestCollection()
                 + DefaultOut;
 
-            public static string GenericCollectionMarshallingArityMismatch => TSignatureTestProvider.BasicParameterByValue("TestCollection<int>", DisableRuntimeMarshalling)
+            public string GenericCollectionMarshallingArityMismatch => _provider.BasicParameterByValue("TestCollection<int>", DisableRuntimeMarshalling)
                 + @"
 [NativeMarshalling(typeof(Marshaller<,,>))]
 class TestCollection<T> {}
@@ -278,14 +296,22 @@ static unsafe class Marshaller<T, U, TUnmanagedElement> where TUnmanagedElement
 }
 ";
 
-            public static string CustomElementMarshalling => TSignatureTestProvider.CustomElementMarshalling("TestCollection<int>", "CustomIntMarshaller")
+            public string CustomElementMarshalling => _provider.CustomElementMarshalling("TestCollection<int>", "CustomIntMarshaller")
                 + TestCollection()
                 + Default
                 + CustomIntMarshaller;
         }
 
-        public static class Stateful
+        public class StatefulSnippets
         {
+            private readonly TSignatureTestProvider _provider;
+            private readonly CustomCollectionMarshallingCodeSnippets<TSignatureTestProvider> _snippets;
+            public StatefulSnippets(CustomCollectionMarshallingCodeSnippets<TSignatureTestProvider> snippets, TSignatureTestProvider provider)
+            {
+                _provider = provider;
+                _snippets = snippets;
+            }
+
             public const string In = @"
 [ContiguousCollectionMarshaller]
 [CustomMarshaller(typeof(TestCollection<>), MarshalMode.ManagedToUnmanagedIn, typeof(Marshaller<,>.In))]
@@ -420,93 +446,93 @@ static unsafe class Marshaller<T, TUnmanagedElement> where TUnmanagedElement : u
     }
 }
 ";
-            public static string ByValue<T>() => ByValue(typeof(T).ToString());
-            public static string ByValue(string elementType) => TSignatureTestProvider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
+            public string ByValue<T>() => ByValue(typeof(T).ToString());
+            public string ByValue(string elementType) => _provider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + In;
 
-            public static string ByValueWithPinning<T>() => ByValueWithPinning(typeof(T).ToString());
-            public static string ByValueWithPinning(string elementType) => TSignatureTestProvider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
+            public string ByValueWithPinning<T>() => ByValueWithPinning(typeof(T).ToString());
+            public string ByValueWithPinning(string elementType) => _provider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + InPinnable;
 
-            public static string ByValueWithStaticPinning<T>() => ByValueWithStaticPinning(typeof(T).ToString());
-            public static string ByValueWithStaticPinning(string elementType) => TSignatureTestProvider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
+            public string ByValueWithStaticPinning<T>() => ByValueWithStaticPinning(typeof(T).ToString());
+            public string ByValueWithStaticPinning(string elementType) => _provider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + InStaticPinnable;
 
-            public static string ByValueCallerAllocatedBuffer<T>() => ByValueCallerAllocatedBuffer(typeof(T).ToString());
-            public static string ByValueCallerAllocatedBuffer(string elementType) => TSignatureTestProvider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
+            public string ByValueCallerAllocatedBuffer<T>() => ByValueCallerAllocatedBuffer(typeof(T).ToString());
+            public string ByValueCallerAllocatedBuffer(string elementType) => _provider.BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + InBuffer;
 
-            public static string DefaultMarshallerParametersAndModifiers<T>() => DefaultMarshallerParametersAndModifiers(typeof(T).ToString());
-            public static string DefaultMarshallerParametersAndModifiers(string elementType) => TSignatureTestProvider.MarshalUsingCollectionCountInfoParametersAndModifiers($"TestCollection<{elementType}>")
+            public string DefaultMarshallerParametersAndModifiers<T>() => DefaultMarshallerParametersAndModifiers(typeof(T).ToString());
+            public string DefaultMarshallerParametersAndModifiers(string elementType) => _provider.MarshalUsingCollectionCountInfoParametersAndModifiers($"TestCollection<{elementType}>")
                 + TestCollection()
                 + Ref;
 
-            public static string CustomMarshallerParametersAndModifiers<T>() => CustomMarshallerParametersAndModifiers(typeof(T).ToString());
-            public static string CustomMarshallerParametersAndModifiers(string elementType) => TSignatureTestProvider.MarshalUsingCollectionParametersAndModifiers($"TestCollection<{elementType}>", $"Marshaller<,>")
+            public string CustomMarshallerParametersAndModifiers<T>() => CustomMarshallerParametersAndModifiers(typeof(T).ToString());
+            public string CustomMarshallerParametersAndModifiers(string elementType) => _provider.MarshalUsingCollectionParametersAndModifiers($"TestCollection<{elementType}>", $"Marshaller<,>")
                 + TestCollection(defineNativeMarshalling: false)
                 + Ref;
 
-            public static string CustomMarshallerReturnValueLength<T>() => CustomMarshallerReturnValueLength(typeof(T).ToString());
-            public static string CustomMarshallerReturnValueLength(string elementType) => TSignatureTestProvider.MarshalUsingCollectionReturnValueLength($"TestCollection<{elementType}>", $"Marshaller<,>")
+            public string CustomMarshallerReturnValueLength<T>() => CustomMarshallerReturnValueLength(typeof(T).ToString());
+            public string CustomMarshallerReturnValueLength(string elementType) => _provider.MarshalUsingCollectionReturnValueLength($"TestCollection<{elementType}>", $"Marshaller<,>")
                 + TestCollection(defineNativeMarshalling: false)
                 + Ref;
 
-            public static string NativeToManagedOnlyOutParameter<T>() => NativeToManagedOnlyOutParameter(typeof(T).ToString());
-            public static string NativeToManagedOnlyOutParameter(string elementType) => CollectionOutParameter($"TestCollection<{elementType}>")
+            public string NativeToManagedOnlyOutParameter<T>() => NativeToManagedOnlyOutParameter(typeof(T).ToString());
+            public string NativeToManagedOnlyOutParameter(string elementType) => _snippets.CollectionOutParameter($"TestCollection<{elementType}>")
                 + TestCollection()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyOutParameter<T>() => NativeToManagedFinallyOnlyOutParameter(typeof(T).ToString());
-            public static string NativeToManagedFinallyOnlyOutParameter(string elementType) => CollectionOutParameter($"TestCollection<{elementType}>")
+            public string NativeToManagedFinallyOnlyOutParameter<T>() => NativeToManagedFinallyOnlyOutParameter(typeof(T).ToString());
+            public string NativeToManagedFinallyOnlyOutParameter(string elementType) => _snippets.CollectionOutParameter($"TestCollection<{elementType}>")
                 + TestCollection()
                 + OutGuaranteed;
 
-            public static string NativeToManagedOnlyReturnValue<T>() => NativeToManagedOnlyReturnValue(typeof(T).ToString());
-            public static string NativeToManagedOnlyReturnValue(string elementType) => CollectionReturnType($"TestCollection<{elementType}>")
+            public string NativeToManagedOnlyReturnValue<T>() => NativeToManagedOnlyReturnValue(typeof(T).ToString());
+            public string NativeToManagedOnlyReturnValue(string elementType) => _snippets.CollectionReturnType($"TestCollection<{elementType}>")
                 + TestCollection()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyReturnValue<T>() => NativeToManagedFinallyOnlyReturnValue(typeof(T).ToString());
-            public static string NativeToManagedFinallyOnlyReturnValue(string elementType) => CollectionReturnType($"TestCollection<{elementType}>")
+            public string NativeToManagedFinallyOnlyReturnValue<T>() => NativeToManagedFinallyOnlyReturnValue(typeof(T).ToString());
+            public string NativeToManagedFinallyOnlyReturnValue(string elementType) => _snippets.CollectionReturnType($"TestCollection<{elementType}>")
                 + TestCollection()
                 + OutGuaranteed;
 
-            public static string NonBlittableElementParametersAndModifiers => DefaultMarshallerParametersAndModifiers("Element")
+            public string NonBlittableElementParametersAndModifiers => DefaultMarshallerParametersAndModifiers("Element")
                 + NonBlittableElement
                 + ElementMarshaller;
 
-            public static string NonBlittableElementByValue => ByValue("Element")
+            public string NonBlittableElementByValue => ByValue("Element")
                 + NonBlittableElement
                 + ElementIn;
 
-            public static string NonBlittableElementNativeToManagedOnlyOutParameter => NativeToManagedOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedOnlyOutParameter => NativeToManagedOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
 
-            public static string NonBlittableElementNativeToManagedFinallyOnlyOutParameter => NativeToManagedOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedFinallyOnlyOutParameter => NativeToManagedOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
-            public static string NonBlittableElementNativeToManagedOnlyReturnValue => NativeToManagedOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedOnlyReturnValue => NativeToManagedOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
 
-            public static string NonBlittableElementNativeToManagedFinallyOnlyReturnValue => NativeToManagedOnlyOutParameter("Element")
+            public string NonBlittableElementNativeToManagedFinallyOnlyReturnValue => NativeToManagedOnlyOutParameter("Element")
                 + NonBlittableElement
                 + ElementOut;
 
-            public static string DefaultModeByValueInParameter => TSignatureTestProvider.BasicParameterByValue($"TestCollection<int>", DisableRuntimeMarshalling)
+            public string DefaultModeByValueInParameter => _provider.BasicParameterByValue($"TestCollection<int>", DisableRuntimeMarshalling)
                 + TestCollection()
                 + DefaultIn;
 
-            public static string DefaultModeReturnValue => CollectionOutParameter($"TestCollection<int>")
+            public string DefaultModeReturnValue => _snippets.CollectionOutParameter($"TestCollection<int>")
                 + TestCollection()
                 + DefaultOut;
 
-            public static string CustomElementMarshalling => TSignatureTestProvider.CustomElementMarshalling("TestCollection<int>", "CustomIntMarshaller")
+            public string CustomElementMarshalling => _provider.CustomElementMarshalling("TestCollection<int>", "CustomIntMarshaller")
                 + TestCollection()
                 + Ref
                 + CustomIntMarshaller;
index 3aad3ac..ab55235 100644 (file)
@@ -3,9 +3,19 @@
 
 namespace Microsoft.Interop.UnitTests
 {
-    public static class CustomStructMarshallingCodeSnippets<TSignatureTestProvider>
+    public class CustomStructMarshallingCodeSnippets<TSignatureTestProvider>
         where TSignatureTestProvider : ICustomMarshallingSignatureTestProvider
     {
+        readonly TSignatureTestProvider _provider;
+        public StatelessSnippets Stateless { get; }
+        public StatefulSnippets Stateful { get; }
+        public CustomStructMarshallingCodeSnippets(TSignatureTestProvider provider)
+        {
+            _provider = provider;
+            Stateless = new StatelessSnippets(provider);
+            Stateful = new StatefulSnippets(provider);
+        }
+
         private static readonly string UsingSystemRuntimeInteropServicesMarshalling = "using System.Runtime.InteropServices.Marshalling;";
 
         public static string NonBlittableUserDefinedType(bool defineNativeMarshalling = true) => $@"
@@ -26,7 +36,7 @@ public class Marshaller
     public static Native ConvertToUnmanaged(S s) => default;
 }
 ";
-        public static string NonStaticMarshallerEntryPoint => TSignatureTestProvider.BasicParameterByValue("S")
+        public string NonStaticMarshallerEntryPoint => _provider.BasicParameterByValue("S")
             + NonBlittableUserDefinedType()
             + NonStatic;
 
@@ -40,13 +50,19 @@ public struct Marshaller
     public Native ToUnmanaged() => default;
 }
 ";
-        public static string StructMarshallerEntryPoint => TSignatureTestProvider.BasicParameterByValue("S")
+        public string StructMarshallerEntryPoint => _provider.BasicParameterByValue("S")
             + NonBlittableUserDefinedType()
             + Struct;
 
 
-        public static class Stateless
+        public class StatelessSnippets
         {
+            public readonly TSignatureTestProvider _provider;
+            public StatelessSnippets(TSignatureTestProvider provider)
+            {
+                this._provider = provider;
+            }
+
             private static string In = @"
 [CustomMarshaller(typeof(S), MarshalMode.ManagedToUnmanagedIn, typeof(Marshaller))]
 [CustomMarshaller(typeof(S), MarshalMode.UnmanagedToManagedOut, typeof(Marshaller))]
@@ -161,89 +177,94 @@ public static class Marshaller
     public static S ConvertToManaged(Native n) => default;
 }
 ";
-            public static string ManagedToNativeOnlyOutParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("out", "S")
+            public string ManagedToNativeOnlyOutParameter => _provider.BasicParameterWithByRefModifier("out", "S")
                 + NonBlittableUserDefinedType()
                 + In;
 
-            public static string NativeToManagedOnlyOutParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("out", "S")
+            public string NativeToManagedOnlyOutParameter => _provider.BasicParameterWithByRefModifier("out", "S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyOutParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("out", "S")
+            public string NativeToManagedFinallyOnlyOutParameter => _provider.BasicParameterWithByRefModifier("out", "S")
                 + NonBlittableUserDefinedType()
                 + OutGuaranteed;
 
-            public static string ManagedToNativeOnlyReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string ManagedToNativeOnlyReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + In;
 
-            public static string NativeToManagedOnlyReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string NativeToManagedOnlyReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string NativeToManagedFinallyOnlyReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedOnlyInParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("in", "S")
+            public string NativeToManagedOnlyInParameter => _provider.BasicParameterWithByRefModifier("in", "S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyInParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("in", "S")
+            public string NativeToManagedFinallyOnlyInParameter => _provider.BasicParameterWithByRefModifier("in", "S")
                 + NonBlittableUserDefinedType()
                 + OutGuaranteed;
 
-            public static string ParametersAndModifiers = TSignatureTestProvider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
+            public string ParametersAndModifiers => _provider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
                 + NonBlittableUserDefinedType(defineNativeMarshalling: true)
                 + Default;
 
-            public static string MarshalUsingParametersAndModifiers = TSignatureTestProvider.MarshalUsingParametersAndModifiers("S", "Marshaller")
+            public string MarshalUsingParametersAndModifiers => _provider.MarshalUsingParametersAndModifiers("S", "Marshaller")
                 + NonBlittableUserDefinedType(defineNativeMarshalling: false)
                 + Default;
 
-            public static string ByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string ByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + In;
 
-            public static string ByValueOutParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string ByValueOutParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string StackallocByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string StackallocByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + InBuffer;
 
-            public static string PinByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string PinByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + InPinnable;
 
-            public static string StackallocParametersAndModifiersNoRef = TSignatureTestProvider.BasicParametersAndModifiersNoRef("S")
+            public string StackallocParametersAndModifiersNoRef => _provider.BasicParametersAndModifiersNoRef("S")
                 + NonBlittableUserDefinedType()
                 + InOutBuffer;
 
-            public static string RefParameter = TSignatureTestProvider.BasicParameterWithByRefModifier("ref", "S")
+            public string RefParameter => _provider.BasicParameterWithByRefModifier("ref", "S")
                 + NonBlittableUserDefinedType()
                 + Ref;
 
-            public static string StackallocOnlyRefParameter = TSignatureTestProvider.BasicParameterWithByRefModifier("ref", "S")
+                public string StackallocOnlyRefParameter => _provider.BasicParameterWithByRefModifier("ref", "S")
                 + NonBlittableUserDefinedType()
                 + InOutBuffer;
 
-            public static string OptionalStackallocParametersAndModifiers = TSignatureTestProvider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
+            public string OptionalStackallocParametersAndModifiers => _provider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
                 + NonBlittableUserDefinedType()
                 + DefaultOptionalBuffer;
 
-            public static string DefaultModeByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string DefaultModeByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + DefaultIn;
 
-            public static string DefaultModeReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string DefaultModeReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + DefaultOut;
         }
 
-        public static class Stateful
+        public class StatefulSnippets
         {
+            private readonly TSignatureTestProvider _provider;
+            public StatefulSnippets (TSignatureTestProvider provider)
+            {
+                _provider = provider;
+            }
             private static string In = @"
 [CustomMarshaller(typeof(S), MarshalMode.ManagedToUnmanagedIn, typeof(M))]
 [CustomMarshaller(typeof(S), MarshalMode.UnmanagedToManagedOut, typeof(M))]
@@ -454,95 +475,95 @@ public static class Marshaller
     }
 }
 ";
-            public static string ManagedToNativeOnlyOutParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("out", "S")
+            public string ManagedToNativeOnlyOutParameter => _provider.BasicParameterWithByRefModifier("out", "S")
                 + NonBlittableUserDefinedType()
                 + In;
 
-            public static string NativeToManagedOnlyOutParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("out", "S")
+            public string NativeToManagedOnlyOutParameter => _provider.BasicParameterWithByRefModifier("out", "S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyOutParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("out", "S")
+            public string NativeToManagedFinallyOnlyOutParameter => _provider.BasicParameterWithByRefModifier("out", "S")
                 + NonBlittableUserDefinedType()
                 + OutGuaranteed;
 
-            public static string ManagedToNativeOnlyReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string ManagedToNativeOnlyReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + In;
 
-            public static string NativeToManagedOnlyReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string NativeToManagedOnlyReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string NativeToManagedFinallyOnlyReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedOnlyInParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("in", "S")
+            public string NativeToManagedOnlyInParameter => _provider.BasicParameterWithByRefModifier("in", "S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string NativeToManagedFinallyOnlyInParameter => TSignatureTestProvider.BasicParameterWithByRefModifier("in", "S")
+            public string NativeToManagedFinallyOnlyInParameter => _provider.BasicParameterWithByRefModifier("in", "S")
                 + NonBlittableUserDefinedType()
                 + OutGuaranteed;
 
-            public static string ParametersAndModifiers = TSignatureTestProvider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
+            public string ParametersAndModifiers => _provider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
                 + NonBlittableUserDefinedType(defineNativeMarshalling: true)
                 + Default;
 
-            public static string ParametersAndModifiersWithFree = TSignatureTestProvider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
+            public string ParametersAndModifiersWithFree => _provider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
                 + NonBlittableUserDefinedType(defineNativeMarshalling: true)
                 + DefaultWithFree;
 
-            public static string ParametersAndModifiersWithOnInvoked = TSignatureTestProvider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
+            public string ParametersAndModifiersWithOnInvoked => _provider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
                 + NonBlittableUserDefinedType(defineNativeMarshalling: true)
                 + DefaultWithOnInvoked;
 
-            public static string MarshalUsingParametersAndModifiers = TSignatureTestProvider.MarshalUsingParametersAndModifiers("S", "Marshaller")
+            public string MarshalUsingParametersAndModifiers => _provider.MarshalUsingParametersAndModifiers("S", "Marshaller")
                 + NonBlittableUserDefinedType(defineNativeMarshalling: false)
                 + Default;
 
-            public static string ByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string ByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + In;
 
-            public static string ByValueOutParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string ByValueOutParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + Out;
 
-            public static string StackallocByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string StackallocByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + InBuffer;
 
-            public static string PinByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string PinByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + InStatelessPinnable;
 
-            public static string MarshallerPinByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string MarshallerPinByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + InPinnable;
 
-            public static string StackallocParametersAndModifiersNoRef = TSignatureTestProvider.BasicParametersAndModifiersNoRef("S")
+            public string StackallocParametersAndModifiersNoRef => _provider.BasicParametersAndModifiersNoRef("S")
                 + NonBlittableUserDefinedType()
                 + InOutBuffer;
 
-            public static string RefParameter = TSignatureTestProvider.BasicParameterWithByRefModifier("ref", "S")
+            public string RefParameter => _provider.BasicParameterWithByRefModifier("ref", "S")
                 + NonBlittableUserDefinedType()
                 + Ref;
 
-            public static string StackallocOnlyRefParameter = TSignatureTestProvider.BasicParameterWithByRefModifier("ref", "S")
+            public string StackallocOnlyRefParameter => _provider.BasicParameterWithByRefModifier("ref", "S")
                 + NonBlittableUserDefinedType()
                 + InOutBuffer;
 
-            public static string OptionalStackallocParametersAndModifiers = TSignatureTestProvider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
+            public string OptionalStackallocParametersAndModifiers => _provider.BasicParametersAndModifiers("S", UsingSystemRuntimeInteropServicesMarshalling)
                 + NonBlittableUserDefinedType()
                 + DefaultOptionalBuffer;
 
-            public static string DefaultModeByValueInParameter => TSignatureTestProvider.BasicParameterByValue("S")
+            public string DefaultModeByValueInParameter => _provider.BasicParameterByValue("S")
                 + NonBlittableUserDefinedType()
                 + DefaultIn;
 
-            public static string DefaultModeReturnValue => TSignatureTestProvider.BasicReturnType("S")
+            public string DefaultModeReturnValue => _provider.BasicReturnType("S")
                 + NonBlittableUserDefinedType()
                 + DefaultOut;
         }
index 5dc0464..d27a04e 100644 (file)
@@ -5,28 +5,28 @@ namespace Microsoft.Interop.UnitTests
 {
     public interface ICustomMarshallingSignatureTestProvider
     {
-        public abstract static string BasicParameterByValue(string type, string preDeclaration = "");
+        public string BasicParameterByValue(string type, string preDeclaration = "");
 
-        public abstract static string BasicParameterWithByRefModifier(string byRefModifier, string type, string preDeclaration = "");
+        public string BasicParameterWithByRefModifier(string byRefModifier, string type, string preDeclaration = "");
 
-        public abstract static string BasicReturnType(string type, string preDeclaration = "");
+        public string BasicReturnType(string type, string preDeclaration = "");
 
-        public abstract static string BasicParametersAndModifiers(string typeName, string preDeclaration = "");
+        public string BasicParametersAndModifiers(string typeName, string preDeclaration = "");
 
-        public abstract static string BasicParametersAndModifiersNoRef(string typeName, string preDeclaration = "");
+        public string BasicParametersAndModifiersNoRef(string typeName, string preDeclaration = "");
 
-        public abstract static string MarshalUsingParametersAndModifiers(string type, string marshallerType, string preDeclaration = "");
+        public string MarshalUsingParametersAndModifiers(string type, string marshallerType, string preDeclaration = "");
 
-        public abstract static string MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType);
+        public string MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType);
 
-        public abstract static string MarshalUsingCollectionParametersAndModifiers(string type, string marshallerType);
+        public string MarshalUsingCollectionParametersAndModifiers(string type, string marshallerType);
 
-        public abstract static string MarshalUsingCollectionOutConstantLength(string type, string predeclaration);
+        public string MarshalUsingCollectionOutConstantLength(string type, string predeclaration);
 
-        public abstract static string MarshalUsingCollectionReturnConstantLength(string type, string predeclaration);
+        public string MarshalUsingCollectionReturnConstantLength(string type, string predeclaration);
 
-        public abstract static string MarshalUsingCollectionReturnValueLength(string type, string marshallerType);
+        public string MarshalUsingCollectionReturnValueLength(string type, string marshallerType);
 
-        public abstract static string CustomElementMarshalling(string type, string marshallerType, string preDeclaration = "");
+        public string CustomElementMarshalling(string type, string marshallerType, string preDeclaration = "");
     }
 }
index 5aba5d6..6df785a 100644 (file)
@@ -6,8 +6,45 @@ using Microsoft.Interop.UnitTests;
 
 namespace LibraryImportGenerator.UnitTests
 {
-    internal partial class CodeSnippets : ICustomMarshallingSignatureTestProvider
+    internal class CodeSnippets : ICustomMarshallingSignatureTestProvider
     {
+        public CodeSnippets() { }
+        string ICustomMarshallingSignatureTestProvider.BasicParameterByValue(string type, string preDeclaration)
+            => BasicParameterByValue(type, preDeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.BasicParameterWithByRefModifier(string byRefModifier, string type, string preDeclaration)
+            => BasicParameterWithByRefModifier(byRefModifier, type, preDeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.BasicReturnType(string type, string preDeclaration)
+            => BasicReturnType(type, preDeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiers(string typeName, string preDeclaration)
+            => BasicParametersAndModifiers(typeName, preDeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.BasicParametersAndModifiersNoRef(string typeName, string preDeclaration)
+            => BasicParametersAndModifiersNoRef(typeName, preDeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingParametersAndModifiers(string type, string marshallerType, string preDeclaration)
+            => MarshalUsingParametersAndModifiers(type, marshallerType, preDeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType)
+            => MarshalUsingCollectionCountInfoParametersAndModifiers(collectionType);
+
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionParametersAndModifiers(string type, string marshallerType)
+            => MarshalUsingCollectionParametersAndModifiers(type, marshallerType);
+
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionOutConstantLength(string type, string predeclaration)
+            => MarshalUsingCollectionOutConstantLength(type, predeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnConstantLength(string type, string predeclaration)
+            => MarshalUsingCollectionReturnConstantLength(type, predeclaration);
+
+        string ICustomMarshallingSignatureTestProvider.MarshalUsingCollectionReturnValueLength(string type, string marshallerType)
+            => MarshalUsingCollectionReturnValueLength(type, marshallerType);
+
+        string ICustomMarshallingSignatureTestProvider.CustomElementMarshalling(string type, string marshallerType, string preDeclaration)
+            => CustomElementMarshalling(type, marshallerType, preDeclaration);
+
         /// <summary>
         /// Partially define attribute for pre-.NET 7.0
         /// </summary>
@@ -946,7 +983,7 @@ partial class Test
 }}
 "
                     + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.TestCollection()
-                    + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.In
+                    + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.StatelessSnippets.In
                     + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.CustomIntMarshaller;
 
         public static string CustomElementMarshallingUnusedElementIndirectionDepth => $@"
@@ -961,7 +998,7 @@ partial class Test
 }}
 "
             + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.TestCollection()
-            + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.In
+            + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.StatelessSnippets.In
             + CustomCollectionMarshallingCodeSnippets<CodeSnippets>.CustomIntMarshaller;
 
         public static string RecursiveCountElementNameOnReturnValue => $@"
index 630100e..55e6ed6 100644 (file)
@@ -99,15 +99,16 @@ namespace LibraryImportGenerator.UnitTests
             yield return new object[] { ID(), CodeSnippets.MarshalUsingArrayParameterWithSizeParam<bool>(isByRef: false), 2, 0 };
 
             // Custom type marshalling with invalid members
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.NonStaticMarshallerEntryPoint, 2, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.ManagedToNativeOnlyOutParameter, 1, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.ManagedToNativeOnlyReturnValue, 1, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedOnlyInParameter, 1, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.StackallocOnlyRefParameter, 1, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.ManagedToNativeOnlyOutParameter, 1, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.ManagedToNativeOnlyReturnValue, 1, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedOnlyInParameter, 1, 0 };
-            yield return new object[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.StackallocOnlyRefParameter, 1, 0 };
+            CustomStructMarshallingCodeSnippets<CodeSnippets> customStructMarshallingCodeSnippets = new(new CodeSnippets());
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.NonStaticMarshallerEntryPoint, 2, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateless.ManagedToNativeOnlyOutParameter, 1, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateless.ManagedToNativeOnlyReturnValue, 1, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateless.NativeToManagedOnlyInParameter, 1, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateless.StackallocOnlyRefParameter, 1, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateful.ManagedToNativeOnlyOutParameter, 1, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateful.ManagedToNativeOnlyReturnValue, 1, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateful.NativeToManagedOnlyInParameter, 1, 0 };
+            yield return new object[] { ID(), customStructMarshallingCodeSnippets.Stateful.StackallocOnlyRefParameter, 1, 0 };
 
             // Abstract SafeHandle type by reference
             yield return new object[] { ID(), CodeSnippets.BasicParameterWithByRefModifier("ref", "System.Runtime.InteropServices.SafeHandle"), 1, 0 };
@@ -119,7 +120,8 @@ namespace LibraryImportGenerator.UnitTests
             yield return new object[] { ID(), CodeSnippets.MarshalUsingCollectionWithNullElementName, 2, 0 };
 
             // Generic collection marshaller has different arity than collection.
-            yield return new object[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.GenericCollectionMarshallingArityMismatch, 2, 0 };
+            CustomCollectionMarshallingCodeSnippets<CodeSnippets> customCollectionMarshallingCodeSnippets = new(new CodeSnippets());
+            yield return new object[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.GenericCollectionMarshallingArityMismatch, 2, 0 };
 
             yield return new object[] { ID(), CodeSnippets.MarshalAsAndMarshalUsingOnReturnValue, 1, 0 };
             yield return new object[] { ID(), CodeSnippets.CustomElementMarshallingDuplicateElementIndirectionDepth, 1, 0 };
index 668cc60..fd8f2e8 100644 (file)
@@ -126,10 +126,10 @@ namespace LibraryImportGenerator.UnitTests
             // By value non-blittable array
             yield return new[] { ID(), CodeSnippets.ByValueParameterWithModifier("S[]", "Out")
                 + CustomStructMarshallingCodeSnippets<CodeSnippets>.NonBlittableUserDefinedType()
-                + CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.Default };
+                + CustomStructMarshallingCodeSnippets<CodeSnippets>.StatelessSnippets.Default };
             yield return new[] { ID(), CodeSnippets.ByValueParameterWithModifier("S[]", "In, Out")
                 + CustomStructMarshallingCodeSnippets<CodeSnippets>.NonBlittableUserDefinedType()
-                + CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.Default };
+                + CustomStructMarshallingCodeSnippets<CodeSnippets>.StatelessSnippets.Default };
 
             // Enums
             yield return new[] { ID(), CodeSnippets.EnumParameters };
@@ -177,38 +177,39 @@ namespace LibraryImportGenerator.UnitTests
             yield return new[] { ID(), CodeSnippets.SafeHandleWithCustomDefaultConstructorAccessibility(privateCtor: true) };
 
             // Custom type marshalling
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.StructMarshallerEntryPoint };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedFinallyOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedFinallyOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.PinByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.StackallocByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.StackallocParametersAndModifiersNoRef };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.OptionalStackallocParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultModeByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultModeReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.ParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.ParametersAndModifiersWithFree };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.ParametersAndModifiersWithOnInvoked };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.MarshalUsingParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedFinallyOnlyOutParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedFinallyOnlyReturnValue };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.StackallocByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.PinByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.MarshallerPinByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.RefParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.StackallocParametersAndModifiersNoRef };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.OptionalStackallocParametersAndModifiers };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultModeByValueInParameter };
-            yield return new[] { ID(), CustomStructMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultModeReturnValue };
+            CustomStructMarshallingCodeSnippets<CodeSnippets> customStructMarshallingCodeSnippets = new(new CodeSnippets());
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.StructMarshallerEntryPoint };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.NativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.NativeToManagedFinallyOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.NativeToManagedOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.NativeToManagedFinallyOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.ByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.PinByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.StackallocByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.StackallocParametersAndModifiersNoRef };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.OptionalStackallocParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.DefaultModeByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateless.DefaultModeReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.ParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.ParametersAndModifiersWithFree };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.ParametersAndModifiersWithOnInvoked };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.MarshalUsingParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.NativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.NativeToManagedFinallyOnlyOutParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.NativeToManagedOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.NativeToManagedFinallyOnlyReturnValue };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.ByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.StackallocByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.PinByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.MarshallerPinByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.RefParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.StackallocParametersAndModifiersNoRef };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.OptionalStackallocParametersAndModifiers };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.DefaultModeByValueInParameter };
+            yield return new[] { ID(), customStructMarshallingCodeSnippets.Stateful.DefaultModeReturnValue };
 
             // Escaped C# keyword identifiers
             yield return new[] { ID(), CodeSnippets.ByValueParameterWithName("Method", "@event") };
@@ -234,90 +235,91 @@ namespace LibraryImportGenerator.UnitTests
         public static IEnumerable<object[]> CustomCollections()
         {
             // Custom collection marshalling
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValue<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueCallerAllocatedBuffer<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.ByValueWithPinning<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValue<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueCallerAllocatedBuffer<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithPinning<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.ByValueWithStaticPinning<UIntPtr>() };
+            CustomCollectionMarshallingCodeSnippets<CodeSnippets> customCollectionMarshallingCodeSnippets = new(new CodeSnippets());
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValue<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueCallerAllocatedBuffer<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.ByValueWithPinning<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValue<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueCallerAllocatedBuffer<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithPinning<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.ByValueWithStaticPinning<UIntPtr>() };
             yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<byte[]>() };
             yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<sbyte[]>() };
             yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<short[]>() };
@@ -330,83 +332,83 @@ namespace LibraryImportGenerator.UnitTests
             yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<double[]>() };
             yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<IntPtr[]>() };
             yield return new[] { ID(), CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers<UIntPtr[]>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomMarshallerReturnValueLength<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedOnlyOutParameter<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedFinallyOnlyOutParameter<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedOnlyReturnValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NativeToManagedFinallyOnlyReturnValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NestedMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NonBlittableElementByValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NonBlittableElementParametersAndModifiers };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NonBlittableElementNativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NonBlittableElementNativeToManagedFinallyOnlyOutParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NonBlittableElementNativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.NonBlittableElementNativeToManagedFinallyOnlyReturnValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultModeByValueInParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.DefaultModeReturnValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateless.CustomElementMarshalling };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<byte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<sbyte>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<short>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<ushort>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<uint>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<long>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<ulong>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<float>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<double>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<IntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerParametersAndModifiers<UIntPtr>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomMarshallerReturnValueLength<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedOnlyOutParameter<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedFinallyOnlyOutParameter<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedOnlyReturnValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NativeToManagedFinallyOnlyReturnValue<int>() };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NonBlittableElementByValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NonBlittableElementParametersAndModifiers };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NonBlittableElementNativeToManagedOnlyOutParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NonBlittableElementNativeToManagedFinallyOnlyOutParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NonBlittableElementNativeToManagedOnlyReturnValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.NonBlittableElementNativeToManagedFinallyOnlyReturnValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultModeByValueInParameter };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.DefaultModeReturnValue };
-            yield return new[] { ID(), CustomCollectionMarshallingCodeSnippets<CodeSnippets>.Stateful.CustomElementMarshalling };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomMarshallerReturnValueLength<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NativeToManagedOnlyOutParameter<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NativeToManagedFinallyOnlyOutParameter<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NativeToManagedOnlyReturnValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NativeToManagedFinallyOnlyReturnValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NestedMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NonBlittableElementByValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NonBlittableElementParametersAndModifiers };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NonBlittableElementNativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NonBlittableElementNativeToManagedFinallyOnlyOutParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NonBlittableElementNativeToManagedOnlyReturnValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.NonBlittableElementNativeToManagedFinallyOnlyReturnValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultModeByValueInParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.DefaultModeReturnValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateless.CustomElementMarshalling };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<byte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<short>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<uint>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<long>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<float>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<double>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomMarshallerReturnValueLength<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NativeToManagedOnlyOutParameter<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NativeToManagedFinallyOnlyOutParameter<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NativeToManagedOnlyReturnValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NativeToManagedFinallyOnlyReturnValue<int>() };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NonBlittableElementByValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NonBlittableElementParametersAndModifiers };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NonBlittableElementNativeToManagedOnlyOutParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NonBlittableElementNativeToManagedFinallyOnlyOutParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NonBlittableElementNativeToManagedOnlyReturnValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.NonBlittableElementNativeToManagedFinallyOnlyReturnValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultModeByValueInParameter };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.DefaultModeReturnValue };
+            yield return new[] { ID(), customCollectionMarshallingCodeSnippets.Stateful.CustomElementMarshalling };
             yield return new[] { ID(), CodeSnippets.CollectionsOfCollectionsStress };
         }