如何从程序集中检索值

发布于 2024-12-15 15:06:03 字数 457 浏览 3 评论 0原文

我有如下所示的代码 此方法中的“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请帮我爱他 2024-12-22 15:06:03

您应该使用 Assembly.Load("TheLongNameOfYourAssembly")

然后在加载的程序集上您可以执行 GetType

Instead of doing assembly = new Assembly() you should load the assembly where the Type is located by using Assembly.Load("TheLongNameOfYourAssembly")

Then on the loaded assembly you can do a GetType

影子的影子 2024-12-22 15:06:03

就像 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文