/// <summary> /// Registers an action to perform around all other actions /// currently in the chain. The contained part of the chain /// is passed in as an action to the decorator that the decorator /// can choose to run (or not) as needed. /// </summary> /// <remarks> /// <para> /// The value of <see cref="Action" /> will be set to a new instance /// that performs the specified <paramref name="decorator"/> around /// the current <see cref="Action" />. /// </para> /// </remarks> /// <param name="decorator">The decorator to register.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="decorator"/> is null.</exception> public void Around(ActionDecorator decorator) { if (decorator == null) { throw new ArgumentNullException("decorator"); } Action innerAction = Action; action = () => decorator(innerAction); }
public void OneTimeSetUp() { using (var resolver = new DefaultAssemblyResolver()) using (var targetAssembly = resolver.Resolve(AssemblyNameReference.Parse("Cilador.TestAopTarget"), new ReaderParameters { ReadWrite = true })) { var loom = new Loom(); var graphGetter = new CilGraphGetter(); using (var runWithoutReplacementDecoration = new ActionDecorator <string[]>(resolver, graphGetter, RunWithoutReplacementDecoration, name => $"{name}_Decorated")) using (var runWithReplacementDecorator = new ActionDecorator <string>(resolver, graphGetter, RunWithReplacementDecorator)) { loom.WeavableConcepts.Add(new WeavableConcept <MethodDefinition>(new PointCut <MethodDefinition>(m => m.Name == "RunWithoutReplacement"), runWithoutReplacementDecoration)); loom.WeavableConcepts.Add(new WeavableConcept <MethodDefinition>(new PointCut <MethodDefinition>(m => m.Name == "RunWithReplacement"), runWithReplacementDecorator)); loom.Weave(targetAssembly); } targetAssembly.Write(); } }
/// <summary> /// Registers an action to perform around all other actions /// currently in the chain. The contained part of the chain /// is passed in as an action to the decorator that the decorator /// can choose to run (or not) as needed. /// </summary> /// <remarks> /// <para> /// The value of <see cref="Action" /> will be set to a new instance /// that performs the specified <paramref name="decorator"/> around /// the current <see cref="Action" />. /// </para> /// </remarks> /// <param name="decorator">The decorator to register.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="decorator"/> is null.</exception> public void Around(ActionDecorator decorator) { if (decorator == null) throw new ArgumentNullException("decorator"); Action innerAction = Action; action = () => decorator(innerAction); }