سؤال

I wrote the aspect class and the target class 'using C# Visual Studio 2008.net' but every time I run the application to interweave them only the target class executed but I can't execute aspect class i tried to attach references to rapier-loom and tried to uninstall rapier-loom and install it again but the same problem occurs....what is the problem ?

this is the aspect class:

using System;

using Loom;

using Loom.JoinPoints;

namespace HelloAspect
 {

    public class TraceAspect : Aspect
    {
      [Loom.JoinPoints.IncludeAll]
      [Call(Advice.Around)]

      public T Trace<T>([JPContext]Context ctx, params object[] args)
      {
        Console.WriteLine(ctx.Instance + "." + ctx.CurrentMethod.Name + " called");

        ctx.Invoke(args);
        return default(T);
      }
    }

 }

this is the Application method:

using System;

using Loom;

using Loom.JoinPoints;


 namespace HelloAspect
 {

    class Program
    {
       static void Main(string[] args)
       {
          string name;
          Console.Write("Your name: ");
          name = Console.ReadLine();
          TraceAspect aspect1 = new TraceAspect();
          Target target = Loom.Weaver.Create<Target>(aspect1);
          target.Hello(name);
          Console.ReadLine();
       }
    }
 
 }

the Target class is:

public class Target
{
    public virtual void Hello(string name)
    {
        Console.WriteLine("Hello {0}!", name);
    
    }
    
}

لا يوجد حل صحيح

نصائح أخرى

The problem is that you implicitly call the ToString() method of the Target class from your advice method via the ctx.Instance call. This will lead in a endless recursion because ToString is also interwoven by the advice method.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top