有没有办法在运行时设置类型的 GUID?
如何动态设置类型的 Guid?
愚蠢的问题,但我有一个在多个第三方 COM 对象中完全相同的接口,但每个对象都有不同的 GUID。
我有一个看起来像这样的 C# 界面。
[Guid("1F13D3D8-3071-4125-8011-900D2EAC9A7F")]
[InterfaceType(2)]
[TypeLibType(4240)]
public interface UICtrl
{
//stuff
}
我希望能够在运行时根据用户选择加载的 COM 对象动态更改 GUID。我无法更改元数据,并且 Type.Guid 没有设置属性。有什么想法吗?
我无法使用 Remit.Emit,因为调用程序集不使用它。我真的被困住了!
How can I set a type's Guid dynamically?
Silly question, but I have an interface that is the exact same across several third-party COM Objects, but has a different GUID in each.
I have a C# interface that looks like so.
[Guid("1F13D3D8-3071-4125-8011-900D2EAC9A7F")]
[InterfaceType(2)]
[TypeLibType(4240)]
public interface UICtrl
{
//stuff
}
I want to be able to change the GUID dynamically at run time depending on which COM object the user chooses to load. I can't change the meta data, and Type.Guid has no set property. Any ideas?
I can't use Remit.Emit because the calling assembly doesn't use it. I'm really stuck!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我最终通过使用@SLaks 的答案和我自己的答案来解决这个问题。基本上,我获取了我的父界面并从中生成了一个具有我想要的 GUID 的子界面。
So I ended up fixing this by using a part of @SLaks's answer and my own. Basically I took my parent interface and generated a child interface from it which had the GUID I wanted.
尝试创建三个空的
[Guid]
接口,它们继承具有所有成员的基接口。Try making three empty
[Guid]
'd interfaces which inherit a base interface with all of the members.