A namespace is a standard C++ construct for grouping types that have related functionality and for preventing name collisions in libraries. The Windows Runtime type system requires that all public Windows Runtime types, including those in your own code, must be declared in a namespace at namespace scope. Public types that are declared at global scope or nested inside another class will cause a compile-time error.
A .winmd file must have the same name that the root namespace has. For example, a class that's named A.B.C.MyClass can be instantiated only if it's defined in a metadata file that's named A.winmd or A.B.winmd or A.B.C.winmd. The name of the executable is not required to match the .winmd file name.
Member accessibility and visibility
In a private ref class, interface, or delegate, no members are emitted to metadata, even if they have public accessibility. In public ref classes, you can control the visibility of members in metadata independently of their accessibility in your source code. As in standard C++, apply the principle of least privilege; don't make your members visible in metadata unless they absolutely must be.
Use the following access modifiers to control both metadata visibility and source code accessibility.
|Modifier||Meaning||Emitted to metadata?|
|private||The default accessibility. Same meaning as in standard C++.||No|
|protected||Same meaning as in standard C++, both within the app or component and in metadata.||Yes|
|public||Same meaning as in standard C++.||Yes|
||Protected accessibility in metadata, public within the app or component.||Yes|
||Not visible in metadata; protected accessibility within the app or component.|
||The member is public within the app or component, but is not visible in metadata.||No|
Windows Runtime namespaces
The Windows API consists of types that are declared in the Windows::* namespaces. These namespaces are reserved for Windows, and types cannot be added to them. In the Object Browser, you can view these namespaces in the windows.winmd file. For documentation about these namespaces, see Windows API.
The C++/CX define certain types in these namespaces as part of the projection of the Windows Runtime type system.
|default||Contains the built-in numeric and char16 types. These types are in scope in every namespace and a
|Platform||Contains primarily public types that correspond to Windows Runtime types such as
|Platform::Collections||Contains the concrete collection classes that implement the Windows Runtime collection interfaces
|Platform::Details||Contains types that are used by the compiler and are not meant for public consumption.|