在运行时获取命名空间 [英] Getting a namespace at runtime

查看:101
本文介绍了在运行时获取命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,是否可以从函数 SortObjects SomeObjectOnAForm 的引用对象名称空间或dll名称c $ c>在运行时的不同项目中?



项目A

Hi Everyone, is it possible to get a referenced objects namespace or dll name, of the variable SomeObjectOnAForm from inside the function SortObjects in different Project at Runtime?

Project A

Function SortObjects(byref lnkObject as Object)
 'Get lnkObject's Namespace?
End function



项目B


Project B

Private Sub Mainform_Load(sender As Object, e As System.EventArgs) Handles Me.Load
 Dim SomeObjectOnAForm as DataGridView
 SortObjects(SomeObjectOnAForm)
End Sub





先谢谢!!



Thanks in Advance!!

推荐答案

没有获取命名空间之类的东西,因为这不是宾语。命名空间只是该类型全名的一部分,在简单类型名称之前带有''。''。



例如:

There is no such thing as "getting a namespace", because this is not an object. Namespace is merely a part of the full name of the type, something which comes with ''.'' before the simple type name.

For example:
Dim someObject As Object = ' no matter what, something which is not null
Dim type As System.Type = someObject.[GetType]()

' now, compare:
Dim fullyQualifiedName As String = type.FullName
Dim simpleName As String = type.Name
' [EDIT] and this is the namespace itself:
Dim namespace As String = type.Namespace









这就是你从类型中立即找到命名空间的方法: http://msdn.microsoft.com/en-us/library/system.type.namespace.aspx [ ^ ]。



[END EDIT]



在第一种情况下,你将得到名称前缀为namespace的名字,在第二种情况下 - 简单名称。在任何情况下都不需要获取命名空间本身。为简单起见,您可以假设所有类型名称都是完全限定的。在这种情况下,您可以在所有情况下使用所有此类型名称,无论 Imports 指令。



总而言之。



-SA


这篇关于在运行时获取命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆