public void Weave(ModuleIO moduleIO, bool isVerbose) { try { ModuleDefinition definition = moduleIO.Read(); if (IsAlreadyWeaved(definition)) return; foreach (TypeDefinition typeDefinition in definition.Types) { Weave(typeDefinition); } MarkWeaved(definition); moduleIO.Write(); } catch (Exception e) { if (!isVerbose) return; Console.Out.WriteLine( "Error occurred reading/writing assembly {0} and/or its associated pdb...Skipping", moduleIO.AssemblyPath); Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e); } }
public void CanAddIdentifyAttributesBeforeWeaving() { var module = new ModuleIO(@"D:\Projects\BCG_Mailing\IMD\weaver\TestExoProject\bin\debug\TestExoProject.dll"); var definition = module.Read(); CustomAttribute ca = new CustomAttribute (definition.Import (typeof (Publish).GetConstructor (Type.EmptyTypes))); definition.CustomAttributes.Add(ca); definition.Write(@"D:\Projects\BCG_Mailing\IMD\weaver\TestExoProject\bin\debug\NewTestExoProject.dll"); var newModule = new ModuleIO(@"D:\Projects\BCG_Mailing\IMD\weaver\TestExoProject\bin\debug\NewTestExoProject.dll"); var newDef = newModule.Read(); Assert.That(newDef.HasCustomAttributes); Assert.That(newDef.CustomAttributes.Any(attribute => attribute.Constructor.DeclaringType.FullName == typeof(Publish).FullName)); }