Warning for partial ComImport types with members in more than one type part (original) (raw)

The same reasoning applies as the reasoning for why partial enums wouldn't make sense. The meaning of a member in a ComImport type changes based on its order within the type.

There is currently no warning for a pair of source files like this, but there should be:

[ComImport] partial interface ISomeInterface { void Foo(); }

partial interface ISomeInterface { void Bar(); }

There should be no warning for a case like this:

[ComImport] partial interface ISomeInterface { void Foo(); }

[SomeInterface] partial interface ISomeInterface { public struct DoesNotAffectVTable { } }

Why not warn for partial ComImport interfaces in the first place?

The source generator https://github.com/microsoft/CsWin32 is a new official vehicle for consuming Windows platform APIs. It generates most types as partial so that you can add customizations, but it doesn't do this for ComImport interfaces. @AArnott cited the danger described at the top. The use case for a partial ComImport interface was to add attributes:

namespace Windows.Win32.UI.Shell { [CoClass(typeof(ShellLink))] internal partial interface IShellLinkW { } }

This is safe, but adding a member would not be safe. Therefore the warning should only apply if more than one type part has members.