簡體   English   中英

如何從泛型類型中獲取命名空間?

[英]How can I get the namespace from a generic type?

我有一個我指定為某種類型的方法。

例如

public MyLabels GetLabels<T>()
{
    // I'd like to get the namespace of the type that T represents here
}

我怎樣才能做到這一點?

使用TypeNamespace屬性:

typeof(T).Namespace

MSDN

typeof(T).FullName // namespace and class name 
typeof(T).Namespace // namespace, no class name

您可以使用typeof(T).FullName

該字符串包含類名和命名空間。

怎么樣

typeof(T).Namespace;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM