com - Is there any way to set a Type's GUID at runtime? -


how can set type's guid dynamically?

silly question, have interface exact same across several third-party com objects, has different guid in each.

i have c# interface looks so.

[guid("1f13d3d8-3071-4125-8011-900d2eac9a7f")] [interfacetype(2)] [typelibtype(4240)] public interface uictrl {   //stuff } 

i want able change guid dynamically @ run time depending on com object user chooses load. can't change meta data, , type.guid has no set property. ideas?

i can't use remit.emit because calling assembly doesn't use it. i'm stuck!

so ended fixing using part of @slaks's answer , own. took parent interface , generated child interface had guid wanted.

assemblyname aname = new assemblyname("multicasterassembly");             assemblybuilder ab = appdomain.currentdomain.definedynamicassembly(aname, assemblybuilderaccess.run);             modulebuilder mb = ab.definedynamicmodule("multicastermodule");             typebuilder tb = mb.definetype("mainocxmulticaster", typeattributes.public);             tb.setparent(typeof(axuictrleventmulticaster));              constructorinfo cinfo = typeof(guidattribute).getconstructor(new type[] {typeof(string)});             customattributebuilder cab = new customattributebuilder(cinfo, new object[] { mocxtype.guid.tostring() });             tb.setcustomattribute(cab);              constructorbuilder cb = tb.definedefaultconstructor(methodattributes.public);              type childeventmulticaster = tb.createtype();                              object o = activator.createinstance(childeventmulticaster);             childeventmulticaster.invokemember("host", bindingflags.setproperty, null, o, new object[] { }); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -