Capgemini / Cauldron

C# Toolkit
MIT License
77 stars 18 forks source link

Inherited attribute does not work #60

Closed programuotojasgf closed 6 years ago

programuotojasgf commented 6 years ago

Inherited attributes don't work

namespace MethodTimerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            new ConcreteFoo().Bar();
            Console.ReadLine();
        }

    }

    public class ConcreteFoo : Foo
    {
        // [LogEnterExit] -> this does work
        public override int Bar()
        {
            Thread.Sleep(100);
            return 5 * 5;
        }
    }

    public abstract class Foo
    {
        [LogEnterExit] // does not work
        public abstract int Bar();
    }
}

namespace MethodTimerTest
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class LogEnterExitAttribute : Attribute, IMethodInterceptor
    {
        private readonly Stopwatch stopwatch = new Stopwatch();
        public void OnEnter(Type declaringType, object instance, MethodBase methodbase, object[] values)
        {
            Console.WriteLine($"Enter -> {methodbase.ReflectedType.FullName}");
            stopwatch.Start();
        }

        public void OnExit()
        {
            stopwatch.Stop();
            Console.WriteLine($"Exited in {stopwatch.Elapsed}");
        }

        bool IMethodInterceptor.OnException(Exception e)
        {
            stopwatch.Stop();
            Console.WriteLine($"Exception in {stopwatch.Elapsed} -> {e.Message}");
            return true;
        }
    }
}
reflection-emit commented 6 years ago

That is because that is not a part of the features of Cauldron, but I will gladly add it on the next release.


Firma: Capgemini Deutschland GmbH Aufsichtsratsvorsitzender: Antonio Schnieder • Geschäftsführer: Dr. Michael Schulte (Sprecher) • Jost Förster • Dr. Peter Lempp • Dr. Volkmar Varnhagen

Amtsgericht Berlin-Charlottenburg, HRB 98814 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

programuotojasgf commented 6 years ago

Thank you!

Is there an estimate as to when the next release will happen or a way to subscribe to know when a new release is out?

reflection-emit commented 6 years ago

I was actually planning to release it end of next week, but I can certainly upload a prerelease for 2 nuget packages tonight.


Firma: Capgemini Deutschland GmbH Aufsichtsratsvorsitzender: Antonio Schnieder • Geschäftsführer: Dr. Michael Schulte (Sprecher) • Jost Förster • Dr. Peter Lempp • Dr. Volkmar Varnhagen

Amtsgericht Berlin-Charlottenburg, HRB 98814 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

reflection-emit commented 6 years ago

3.0.15-beta nuget package is uploaded.