Coder Social home page Coder Social logo

Comments (3)

pamidur avatar pamidur commented on August 17, 2024

We can definitely hide it from debug session, though I'm not quite sure it is possible with stacktrace without direct modification of it.
Would you sacrifice runtime performance for cleaner stacktrace?

from aspect-injector.

pairbit avatar pairbit commented on August 17, 2024

You must take into account that the methods will not work properly with InjectionPoints.Around:

  1. MethodBase.GetCurrentMethod
  2. Assembly.GetCallingAssembly
  3. new StackTrace()

Source ClassLibrary1:

public class Lib
{
    private static readonly Func<MethodBase> CurrentMethod = MethodBase.GetCurrentMethod;
    private static readonly Func<Assembly> CallingAssembly = Assembly.GetCallingAssembly;

    public static void Test1()
    {
        Log(CurrentMethod(), CallingAssembly(), new StackTrace());
    }

    [Aspect(typeof(TestAspect))]
    public static void Test2()
    {
        Log(CurrentMethod(), CallingAssembly(), new StackTrace());
    }

    static void Log(MethodBase method, Assembly assembly, StackTrace stackTrace)
    {
        Console.WriteLine("CurrentMethod: {0}", method.Name);
        Console.WriteLine("CallingAssembly: {0}", assembly.GetName().Name);
        Console.WriteLine("StackTrace {0}:", stackTrace.FrameCount.ToString());
        foreach (var frame in stackTrace.GetFrames())
        {
            var frameMethod = frame.GetMethod();
            Console.WriteLine("{0}.{1}", frameMethod.DeclaringType.Name, frameMethod.Name);
        }
        Console.WriteLine();
    }
}

class TestAspect
{
    [Advice(InjectionPoints.Around, InjectionTargets.Method)]
    public Object Test(
        [AdviceArgument(AdviceArgumentSource.Arguments)] Object[] args,
        [AdviceArgument(AdviceArgumentSource.Target)] Func<Object[], Object> target)
    {
        return target(args);
    }
}

Source ConsoleApplication1:

class Program
{
    static void Main(string[] args)
    {
        Lib.Test1();
        Lib.Test2();
    }
}

Result:
2016-02-08_1652

from aspect-injector.

pamidur avatar pamidur commented on August 17, 2024

done in 2.0.0-beta1

from aspect-injector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.