Hi, Yeah I'm afraid it's not an easy thing to do :(
You can see how IL-Repack https://github.com/gluck/il-repack is moving entire types across modules. Jb On Sun, Jul 13, 2014 at 4:27 AM, WhyWontItWork <[email protected]> wrote: > Hi, I would like to extract part of a module into its own module using > Mono.Cecil. Specifically, I want to take all types from the System.Net > namespace within System.dll, and move them into My.System.Net.dll. Here is > my code so far. > >>> public static void Main(string[] args) >>> >>> { >>> >>> var assembly = AssemblyDefinition.ReadAssembly("System.dll"); >>> >>> assembly.MainModule.Name = "My.Net"; >>> >>> >>> >>> var def = new List<TypeDefinition> (); >>> >>> >>> foreach (TypeDefinition type in assembly.MainModule.Types) >>> >>> { >>> >>> if (type.Namespace.StartsWith ("System.Net")) { >>> >>> type.Namespace = type.Namespace.Replace("System.Net", >>> "My.System.Net"); >>> >>> } else { >>> >>> def.Add (type); >>> >>> } >>> >>> } >>> >>> >>> foreach (var type in def) >>> >>> { >>> >>> assembly.MainModule.Import(type); >>> >>> assembly.MainModule.Types.Remove(type); >>> >>> } >>> >>> >>> assembly.Write("My.Net.dll"); >>> >>> >>> Console.WriteLine("OK"); >>> >>> Console.ReadLine(); >>> >>> } > > > The application crashes when I write the new assembly. It says : > >> Additional information: Member >> 'System.Collections.Specialized.StringDictionary' is declared in another >> module and needs to be imported > > > I tried to remedy this by adding the Import(type) call, but Im pretty sure > Im doing it wrong. > > This is my first time using Mono.Cecil, so Im sure Im making some errors. I > really wish there was more help online, but I understand this is a new > venture. Any help is appreciated. > > -- > -- > -- > 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/d/optout. -- -- -- 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/d/optout.
