[英]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
}
我怎樣才能做到這一點?
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.