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

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

Implementuje

Przykłady

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

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
    
type MyClass() = class end

namespace global

module Example = 
    let myType = typeof<MyNamespace.MyClass>
    printfn $"Displaying information about {myType}:"
    // Get the namespace of the myClass class.
    printfn $"   Namespace: {myType.Namespace}."
    // Get the name of the ilmodule.
    printfn $"   Module: {myType.Module}."
    // Get the fully qualified type name.
    printfn $"   Fully qualified name: {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 w czasie projektowania, używana głównie do definiowania zakresu w aplikacji i organizowania klas i innych typów w jednej strukturze hierarchicznej. Z punktu widzenia środowiska uruchomieniowego nie ma przestrzeni nazw.

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

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

Dotyczy

Zobacz też