-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Namespaces in .NET are not a first class concept in metadata but are implicit in type names. C++ inline namespaces are namespaces whose contents are implicitly available in the enclosing namespace. E.g.
namespace N {
inline namespace I {
ref class R {};
}
}
The type R
is simply name N.I.R
in the metadata and upon import the C++ compiler does not know whether I
is an inline namespace or not. To help the compiler import this correctly, an assembly-level custom attribute is emitted to the assembly for every inline namespace in the assembly. E.g., for the above we would emit
[CppInlineNamespace("N.I")];
To implement this, we need the attribute System.Runtime.CompilerServices.CppInlineNamespaceAttribute
in System.Runtime.CompilerServices.VisualC.dll:
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class CppInlineNamespaceAttribute : Attribute
{
public CppInlineNamespaceAttribute(string dottedName);
}
}
An explanation of how inline namespaces work is at https://foonathan.net/2018/11/inline-namespaces: