Hey John, There is :)
You can simply write: var constructor = typeof(CompilerGeneratedAttribute).GetConstructors().First(x => x.Parameters.Count == 0) var compilerGeneratedAttributeCtor = ModuleDefinition.Import(constructor); Note that this will create a reference to the executing version of the assembly containing the type CompilerGeneratedAttribute. So if you're modifying a .net 4.0 assembly on .net 4.0 that's not a problem, but if you're modifying a .net 2.0 assembly when running a .net 4.0 program, you will create a reference to the .net 4.0 mscorlib. To avoid this, it's usually best to work only with the Cecil type system. You just need to resolve the reference to the corlib (module.TypeSystem.Corlib), get the type CompilerGeneratedAttribute, and import a reference into your current module. Jb On Sun, Jan 5, 2014 at 2:20 AM, John Galt <[email protected]> wrote: > Hi, > > I'm new to Cecil (great job!) so am still floundering around a bit. > Apologies for such a noob question. > > I just caught myself doing this: > > var compilerGeneratedAttributeCtor = > ModuleDefinition.Import(ModuleDefinition.Import(typeof(CompilerGeneratedAttribute)).Resolve().GetConstructors().First(x > => x.Parameters.Count == 0)); > > And I thought: surely there's a cleaner, easier way. Any thoughts? > > Thanks > > -- > -- > -- > mono-cecil > --- > You received this message because you are subscribed to the Google Groups > "mono-cecil" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. -- -- -- mono-cecil --- You received this message because you are subscribed to the Google Groups "mono-cecil" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
