diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatefulCollectionPinnableReference.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatefulCollectionPinnableReference.cs new file mode 100644 index 00000000000000..f417e7bc314cca --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatefulCollectionPinnableReference.cs @@ -0,0 +1,86 @@ +// 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 SharedTypes.ComInterfaces +{ + [GeneratedComInterface(), Guid("0A52BA7C-E08B-42A4-A1F4-1A2BF2C07E60")] + internal partial interface IStatefulCollectionPinnableReference + { + void Method( + [MarshalUsing(CountElementName = nameof(size))] StatefulCollectionPinnableReference p, + int size); + + void MethodIn( + [MarshalUsing(CountElementName = nameof(size))] in StatefulCollectionPinnableReference pIn, + in int size); + + void MethodRef( + [MarshalUsing(CountElementName = nameof(size))] ref StatefulCollectionPinnableReference pRef, + int size); + + void MethodOut( + [MarshalUsing(CountElementName = nameof(size))] out StatefulCollectionPinnableReference pOut, + out int size); + + [return: MarshalUsing(CountElementName = nameof(size))] + StatefulCollectionPinnableReference Return(int size); + } + + [NativeMarshalling(typeof(StatefulCollectionPinnableReferenceMarshaller<,>))] + internal class StatefulCollectionPinnableReference + { + } + + internal struct StatefulCollectionPinnableReferenceNative + { + public static unsafe explicit operator void*(StatefulCollectionPinnableReferenceNative _) => throw new NotImplementedException(); + public static unsafe explicit operator StatefulCollectionPinnableReferenceNative(void* _) => throw new NotImplementedException(); + } + + [ContiguousCollectionMarshaller] + [CustomMarshaller(typeof(StatefulCollectionPinnableReference<>), MarshalMode.ManagedToUnmanagedRef, typeof(StatefulCollectionPinnableReferenceMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatefulCollectionPinnableReference<>), MarshalMode.UnmanagedToManagedRef, typeof(StatefulCollectionPinnableReferenceMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatefulCollectionPinnableReference<>), MarshalMode.ManagedToUnmanagedOut, typeof(StatefulCollectionPinnableReferenceMarshaller<,>.UnmanagedToManaged))] + [CustomMarshaller(typeof(StatefulCollectionPinnableReference<>), MarshalMode.UnmanagedToManagedIn, typeof(StatefulCollectionPinnableReferenceMarshaller<,>.UnmanagedToManaged))] + [CustomMarshaller(typeof(StatefulCollectionPinnableReference<>), MarshalMode.ManagedToUnmanagedIn, typeof(StatefulCollectionPinnableReferenceMarshaller<,>.ManagedToUnmanaged))] + [CustomMarshaller(typeof(StatefulCollectionPinnableReference<>), MarshalMode.UnmanagedToManagedOut, typeof(StatefulCollectionPinnableReferenceMarshaller<,>.ManagedToUnmanaged))] + internal static class StatefulCollectionPinnableReferenceMarshaller where TUnmanaged : unmanaged + { + public struct Bidirectional + { + public void FromManaged(StatefulCollectionPinnableReference managed) => throw new NotImplementedException(); + public StatefulCollectionPinnableReferenceNative ToUnmanaged() => throw new NotImplementedException(); + public ReadOnlySpan GetManagedValuesSource() => throw new NotImplementedException(); + public Span GetUnmanagedValuesDestination() => throw new NotImplementedException(); + + public void FromUnmanaged(StatefulCollectionPinnableReferenceNative unmanaged) => throw new NotImplementedException(); + public StatefulCollectionPinnableReference ToManaged() => throw new NotImplementedException(); + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => throw new NotImplementedException(); + public Span GetManagedValuesDestination(int numElements) => throw new NotImplementedException(); + + public void Free() => throw new NotImplementedException(); + } + + public struct UnmanagedToManaged + { + public void Free() => throw new NotImplementedException(); + public void FromUnmanaged(StatefulCollectionPinnableReferenceNative unmanaged) => throw new NotImplementedException(); + public StatefulCollectionPinnableReference ToManaged() => throw new NotImplementedException(); + public ReadOnlySpan GetUnmanagedValuesSource(int numElements) => throw new NotImplementedException(); + public Span GetManagedValuesDestination(int numElements) => throw new NotImplementedException(); + } + + public struct ManagedToUnmanaged + { + public void FromManaged(StatefulCollectionPinnableReference managed) => throw new NotImplementedException(); + public StatefulCollectionPinnableReferenceNative ToUnmanaged() => throw new NotImplementedException(); + public ReadOnlySpan GetManagedValuesSource() => throw new NotImplementedException(); + public Span GetUnmanagedValuesDestination() => throw new NotImplementedException(); + public void Free() => throw new NotImplementedException(); + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionPinnableReference.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionPinnableReference.cs new file mode 100644 index 00000000000000..33d478c597b9c6 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionPinnableReference.cs @@ -0,0 +1,85 @@ +// 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 SharedTypes.ComInterfaces +{ + [GeneratedComInterface(), Guid("0A52BA7C-E08B-42A4-A1F4-1A2BF2C07E60")] + internal partial interface IStatelessCollectionPinnableReference + { + void Method( + [MarshalUsing(CountElementName = nameof(size))] StatelessCollectionPinnableReference p, + int size); + + void MethodIn( + [MarshalUsing(CountElementName = nameof(size))] in StatelessCollectionPinnableReference pIn, + in int size); + + void MethodRef( + [MarshalUsing(CountElementName = nameof(size))] ref StatelessCollectionPinnableReference pRef, + int size); + + void MethodOut( + [MarshalUsing(CountElementName = nameof(size))] out StatelessCollectionPinnableReference pOut, + out int size); + + [return: MarshalUsing(CountElementName = nameof(size))] + StatelessCollectionPinnableReference Return(int size); + } + + [NativeMarshalling(typeof(StatelessCollectionPinnableReferenceMarshaller<,>))] + internal class StatelessCollectionPinnableReference + { + } + + internal struct StatelessCollectionPinnableReferenceNative + { + public static unsafe explicit operator void*(StatelessCollectionPinnableReferenceNative _) => throw new NotImplementedException(); + public static unsafe explicit operator StatelessCollectionPinnableReferenceNative(void* _) => throw new NotImplementedException(); + } + + [ContiguousCollectionMarshaller] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.ManagedToUnmanagedRef, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.UnmanagedToManagedRef, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.ElementIn, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.ElementOut, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.ElementRef, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.ManagedToUnmanagedOut, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.UnmanagedToManaged))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.UnmanagedToManagedIn, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.UnmanagedToManaged))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.ManagedToUnmanagedIn, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.ManagedToUnmanaged))] + [CustomMarshaller(typeof(StatelessCollectionPinnableReference<>), MarshalMode.UnmanagedToManagedOut, typeof(StatelessCollectionPinnableReferenceMarshaller<,>.ManagedToUnmanaged))] + internal static class StatelessCollectionPinnableReferenceMarshaller where TUnmanaged : unmanaged + { + public static class Bidirectional + { + public static ref StatelessCollectionPinnableReferenceNative GetPinnableReference(StatelessCollectionPinnableReference managed) => throw new NotImplementedException(); + public static StatelessCollectionPinnableReferenceNative AllocateContainerForUnmanagedElements(StatelessCollectionPinnableReference managed, out int numElements) => throw new NotImplementedException(); + public static StatelessCollectionPinnableReference AllocateContainerForManagedElements(StatelessCollectionPinnableReferenceNative unmanaged, int numElements) => throw new NotImplementedException(); + public static ReadOnlySpan GetManagedValuesSource(StatelessCollectionPinnableReference managed) => throw new NotImplementedException(); + public static Span GetUnmanagedValuesDestination(StatelessCollectionPinnableReferenceNative unmanaged, int numElements) => throw new NotImplementedException(); + public static ReadOnlySpan GetUnmanagedValuesSource(StatelessCollectionPinnableReferenceNative unmanaged, int numElements) => throw new NotImplementedException(); + public static Span GetManagedValuesDestination(StatelessCollectionPinnableReference managed) => throw new NotImplementedException(); + public static void Free(StatelessCollectionPinnableReferenceNative native) { } + } + + public static class UnmanagedToManaged + { + public static StatelessCollectionPinnableReference AllocateContainerForManagedElements(StatelessCollectionPinnableReferenceNative unmanaged, int numElements) => throw new NotImplementedException(); + public static ReadOnlySpan GetUnmanagedValuesSource(StatelessCollectionPinnableReferenceNative unmanaged, int numElements) => throw new NotImplementedException(); + public static Span GetManagedValuesDestination(StatelessCollectionPinnableReference managed) => throw new NotImplementedException(); + public static void Free(StatelessCollectionPinnableReferenceNative native) { } + } + + public static class ManagedToUnmanaged + { + public static ref StatelessCollectionPinnableReferenceNative GetPinnableReference(StatelessCollectionPinnableReference managed) => throw new NotImplementedException(); + public static StatelessCollectionPinnableReferenceNative AllocateContainerForUnmanagedElements(StatelessCollectionPinnableReference managed, out int numElements) => throw new NotImplementedException(); + public static ReadOnlySpan GetManagedValuesSource(StatelessCollectionPinnableReference managed) => throw new NotImplementedException(); + public static Span GetUnmanagedValuesDestination(StatelessCollectionPinnableReferenceNative unmanaged, int numElements) => throw new NotImplementedException(); + public static void Free(StatelessCollectionPinnableReferenceNative native) { } + } + } +}