Capgemini / Cauldron

C# Toolkit
MIT License
76 stars 18 forks source link

Init method in interceptor pulling in method/property/etc information for use in the interception #47

Closed Kazpers closed 6 years ago

Kazpers commented 6 years ago

Ie. pulling in MethodBase and args (for methods) like this:

public void Init(object instance, MethodBase method, object[] args) { TestMessages.Record(string.Format("Init: {0} [{1}]", method.DeclaringType.FullName + "." + method.Name, args.Length)); }

Idea taken from MethodDecorator.Fody, but would be very useful for knowing something about the instance and method/property/anything we are weaving.

reflection-emit commented 6 years ago

All 4 kinds of interceptors have the instance (except you are intercepting static), args and MethodBase. The IMethodInterceptor has it in the OnEnter. The IPropertyGetterInterceptor has it in the OnGet... In this it is part of PropertyInterceptionInfo. The IPropertySetterInterceptor has it in the OnSet, also in the PropertyInterceptionInfo. The IConstructorInterceptor has it also in the OnEnter.

There is also an interface for the property interceptors that force them to move the init to the ctor IPropertyInterceptorInitialize.

Kazpers commented 6 years ago

Thank you!