如何从程序集中检索值
我有如下所示的代码 此方法中的“xmlSerializedType.AssemblyName
”值为 "_Rounded_TreeGOLD, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
,它是用户的程序集名称将类和 'xmlSerializedType.Name
' 定义为 "_Rounded_Tree" 。在这里,我需要将 'xmlSerializedType.Name
' 分配给 'type
' ,例如 "GetType(xmlSerializedType.Name);"
,这样 'type ' 变成 type = {Name = "_Rounded_Tree" FullName = "_Rounded_Tree"} 如何实现这一点,我的意思是我需要为“type”实现什么代码
I have a code like shown below
Here 'xmlSerializableType.AssemblyName
' value in this method coming as "_Rounded_TreeGOLD, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
which is the assembly name of user defined class and 'xmlSerializableType.Name
' as "_Rounded_Tree" . Here i need to assign 'xmlSerializableType.Name
' to 'type
' something like "GetType(xmlSerializableType.Name);"
so that 'type' becomes type = {Name = "_Rounded_Tree" FullName = "_Rounded_Tree"} How to acheive this, i mean What code i need to implement for "type"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
Assembly.Load("TheLongNameOfYourAssembly")
然后在加载的程序集上您可以执行 GetType
Instead of doing
assembly = new Assembly()
you should load the assembly where the Type is located by usingAssembly.Load("TheLongNameOfYourAssembly")
Then on the loaded assembly you can do a GetType
就像 Wouter 所说,使用 Assembly.Load("AssemblyLongName")。
在该程序集中,您可以使用 assembly.GetTypes() 或更好的 assembly.GetExportedTypes() 仅适用于“公共”类型。
迭代类型并检查它们的名称。
如果您有一些常见的基类或更多信息,您可以检查 系统.类型
例如,您可以使用 asmType.BaseType == typeof(yourBaseType) 或
typeof(yourBaseType).IsAssignableFrom(asmType)。
查看 MSDN 链接,我很确定您会在那里找到所需的一切。
如果您确实知道确切的名称 assembly.GetType("yourExactTypeName") 也应该有效。
Like Wouter said, use Assembly.Load("AssemblyLongName").
On that assembly you can use assembly.GetTypes() or, even better assembly.GetExportedTypes() for "public" types only.
Iterate over the Types and check their names.
If you have some common base class or some more information you can check the various methods on System.Type
For instance, you could use asmType.BaseType == typeof(yourBaseType) or
typeof(yourBaseType).IsAssignableFrom(asmType).
Have a look at the MSDN link, im pretty sure you will find everything needed there.
If you do know the exact Name assembly.GetType("yourExactTypeName") should work, too.