Do you throw args.Instace to your type? Based on what you wrote, I would suggest that your "FeatureEnabled" should be defined through an interface.
public interface IHasFeature { bool IsFeatureEnabled { get; set; } void SomeOtherMethod(); }
then use
((IHasFeature)args.Instance).SomeOtherMethod();
Then apply the aspect to this interface.
[assembly: MyApp.MyAspect(AttributeTargetTypes = "MyApp.IHasFeature")]
or directly on the interface
[MyAspect] public interface IHasFeature
Update: Sorry, Gael is right. Sorry about that. Use the CompileTimeValidate method in order to LIMIT aspect at compile time.
public override bool CompileTimeValidate(System.Reflection.MethodBase method) { bool isCorrectType = (Check for correct type here) return isCorrectType; }
For more information, see my post http://www.sharpcrafters.com/blog/post/Day-9-Aspect-Lifetime-Scope-Part-1.aspx
source share