Type.Namespace Właściwość

Definicja

Pobiera przestrzeń nazw elementu Type .

public:
 abstract property System::String ^ Namespace { System::String ^ get(); };
public abstract string Namespace { get; }
public abstract string? Namespace { get; }
member this.Namespace : string
Public MustOverride ReadOnly Property Namespace As String

Wartość właściwości

String

Przestrzeń nazw ; jeśli bieżące wystąpienie nie Type ma przestrzeni nazw lub reprezentuje parametr null ogólny.

Implementuje

Przykłady

W poniższym przykładzie pokazano użycie właściwości Namespace i oraz metody metody Module ToString Type .

using namespace System;

namespace MyNamespace
{
   ref class MyClass
   {
   };
}

void main()
{
      Type^ myType = MyNamespace::MyClass::typeid;
      Console::WriteLine("Displaying information about {0}:", myType );
      
      // Get the namespace of the class MyClass.
      Console::WriteLine("   Namespace: {0}", myType->Namespace );
      
      // Get the name of the module.
      Console::WriteLine("   Module: {0}", myType->Module );
      
      // Get the fully qualified common language runtime namespace.
      Console::WriteLine("   Fully qualified type: {0}", myType );
}
// The example displays the following output:
//    Displaying information about MyNamespace.MyClass:
//       Namespace: MyNamespace
//       Module: type_tostring.exe
//       Fully qualified name: MyNamespace.MyClass
using System;

namespace MyNamespace
{
    class MyClass
    {
    }
}

public class Example
{
    public static void Main()
    {
         Type myType = typeof(MyNamespace.MyClass);
         Console.WriteLine("Displaying information about {0}:", myType);
         // Get the namespace of the myClass class.
         Console.WriteLine("   Namespace: {0}.", myType.Namespace);
         // Get the name of the module.
         Console.WriteLine("   Module: {0}.", myType.Module);
         // Get the fully qualified type name.
         Console.WriteLine("   Fully qualified name: {0}.", myType.ToString());
    }
}
// The example displays the following output:
//    Displaying information about MyNamespace.MyClass:
//       Namespace: MyNamespace.
//       Module: type_tostring.exe.
//       Fully qualified name: MyNamespace.MyClass.
Namespace MyNamespace
    Class [MyClass]
    End Class 
End Namespace 

Public Class Example
    Public Shared Sub Main()
         Dim myType As Type = GetType(MyNamespace.MyClass)
         Console.WriteLine(", myType)
         ' Get the namespace of the MyClass class.
         Console.WriteLine("   Namespace: {0}.", myType.Namespace)
         ' Get the name of the module.
         Console.WriteLine("   Module: {0}.", myType.Module)
         ' Get the fully qualified type name.
         Console.WriteLine("   Fully qualified name: {0}.", myType.ToString())
    End Sub
End Class
' The example displays the following output:
'       Displaying information about MyNamespace.MyClass:
'          Namespace: MyNamespace.
'          Module: type_tostring.exe.
'          Fully qualified name: MyNamespace.MyClass.

Uwagi

Przestrzeń nazw to logiczna wygoda nazewnictwa czasu projektowania używana głównie do definiowania zakresu w aplikacji oraz organizowania klas i innych typów w ramach jednej struktury hierarchicznej. Z punktu widzenia środowiska uruchomieniowego nie ma żadnych przestrzeni nazw.

Jeśli bieżący reprezentuje Type skonstruowany typ ogólny, ta właściwość zwraca przestrzeń nazw zawierającą definicję typu ogólnego. Podobnie, jeśli bieżący reprezentuje parametr ogólny , ta właściwość zwraca przestrzeń nazw zawierającą definicję typu Type T ogólnego, która definiuje T .

Jeśli bieżący obiekt reprezentuje parametr ogólny, a definicja typu ogólnego nie jest dostępna, na przykład dla typu sygnatury zwróconego przez parametr , ta Type MakeGenericMethodParameter właściwość zwraca wartość null .

Dotyczy

Zobacz też