Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public ComInterfaceMarshallingInfoProvider(Compilation compilation)

public MarshallingInfo? ParseAttribute(AttributeData attributeData, ITypeSymbol type, int indirectionDepth, UseSiteAttributeProvider useSiteAttributes, GetMarshallingInfoCallback marshallingInfoCallback)
{
// If the type has a NativeMarshallingAttribute, defer to that parser by returning null
if (type.GetAttributes().Any(attr => attr.AttributeClass?.ToDisplayString() == TypeNames.NativeMarshallingAttribute))
{
return null;
}

return CreateComInterfaceMarshallingInfo(_compilation, type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,21 @@ public Bidirectional(IComInterfaceAttributeProvider attributeProvider)

public IComInterfaceAttributeProvider AttributeProvider { get; }
}

public string ComInterfaceWithNativeMarshalling => $$"""
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

[assembly:DisableRuntimeMarshalling]

{{GeneratedComInterface()}}
[NativeMarshalling(typeof(UniqueComInterfaceMarshaller<IFoo>))]
partial interface IFoo
{
void DoWorkTogether(IFoo foo);
}
""";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ public static IEnumerable<object[]> ComInterfaceSnippetsToCompile()
yield return new object[] { ID(), codeSnippets.ForwarderWithPreserveSigAndRefKind("ref readonly") };
yield return new object[] { ID(), codeSnippets.ForwarderWithPreserveSigAndRefKind("in") };
yield return new object[] { ID(), codeSnippets.ForwarderWithPreserveSigAndRefKind("out") };
yield return new object[] { ID(), codeSnippets.ComInterfaceWithNativeMarshalling };
}

public static IEnumerable<object[]> ManagedToUnmanagedComInterfaceSnippetsToCompile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1526,5 +1526,25 @@ public void Free() { }
}
}
""";

public static string ComInterfaceWithNativeMarshallingInLibraryImport => """
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

[GeneratedComInterface]
[Guid("0E7204B5-4B61-4E06-B872-82BA652F2ECA")]
[NativeMarshalling(typeof(UniqueComInterfaceMarshaller<IFoo>))]
partial interface IFoo
{
void DoWork();
}

static partial class PInvokes
{
[LibraryImport("lib")]
[return: MarshalAs(UnmanagedType.I1)]
public static partial bool TryGetFoo(out IFoo foo);
}
""";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompile()

// Type-level interop generator trigger attributes
yield return new[] { ID(), CodeSnippets.GeneratedComInterface };
yield return new[] { ID(), CodeSnippets.ComInterfaceWithNativeMarshallingInLibraryImport };

// Parameter modifiers
yield return new[] { ID(), CodeSnippets.SingleParameterWithModifier("int", "scoped ref") };
Expand Down
Loading