public AroundMethodWeaver(DemonTypes demonTypes, MethodDefinition target, MethodReference advice, FieldDefinition adviceField) { _demonTypes = demonTypes; _target = target; _advice = advice; _adviceField = adviceField; _il = target.Body.GetILProcessor(); _emitter = EmitterFactory.GetAppend(_il); }
public BeforeMethodWeaver(DemonTypes demonTypes, MethodDefinition target, MethodReference advice, FieldDefinition adviceField) { _demonTypes = demonTypes; _target = target; _advice = advice; _adviceField = adviceField; _il = target.Body.GetILProcessor(); var originalFirstInstruction = target.Body.Instructions[0]; _emitter = EmitterFactory.Get(_il, i => _il.InsertBefore(originalFirstInstruction, i)); _insertBeforeOriginalFirst = i => _il.InsertBefore(originalFirstInstruction, i); }
public static void Weave(string[] assemblyPaths) { var modules = new List <ModuleDefinition>(); ModuleDefinition demonModule = null; try { demonModule = HackyLoadDemonModule(); var demonTypes = DemonTypes.FromModule(demonModule); foreach (var path in assemblyPaths) { modules.Add(ModuleDefinition.ReadModule(path, new ReaderParameters { ReadWrite = true })); } var allTypes = modules.SelectMany(m => m.GetTypes()).ToList(); var advice = AspectModelBuilder.FromTypeDefinitions(allTypes); //todo filter to not run on aspects accidentally foreach (var type in allTypes) { TypeWeaver.Weave(type, advice, demonTypes); } //todo check file locking issues foreach (var module in modules) { module.Write(); } } finally { foreach (var module in modules) { module.Dispose(); } demonModule?.Dispose(); } }
public TypeWeaver(TypeDefinition type, List <AdviceModel> adviceModels, DemonTypes demonTypes) => (_type, _adviceModels, _demonTypes) = (type, adviceModels, demonTypes);