private static bool CheckTarget(TargetMethodContext targetMethodContext, InjectionTargets target) { var targetMethod = targetMethodContext.TargetMethod; if (targetMethod.IsAbstract || targetMethod.IsPInvokeImpl) { return(false); } if (targetMethod.IsConstructor) { return(target == InjectionTargets.Constructor); } if (targetMethod.IsGetter) { return(target == InjectionTargets.Getter); } if (targetMethod.IsSetter) { return(target == InjectionTargets.Setter); } if (targetMethod.IsAddOn) { return(target == InjectionTargets.EventAdd); } if (targetMethod.IsRemoveOn) { return(target == InjectionTargets.EventRemove); } if (!targetMethod.CustomAttributes.HasAttributeOfType <CompilerGeneratedAttribute>()) { return(target == InjectionTargets.Method); } return(false); }
public AdviceAttribute(InjectionPoints points, InjectionTargets targets) { Points = points; Targets = targets; }
internal static void ValidateAdviceInjectionContext(Contexts.AdviceInjectionContext context, InjectionTargets target) { //if (target == InjectionTargets.Constructor) //{ // if (!context.AdviceMethod.ReturnType.IsTypeOf(typeof(void))) // throw new CompilationException("Advice of InjectionTargets.Constructor can be System.Void only", context.AdviceMethod); //} if (context.InjectionPoint == InjectionPoints.After || context.InjectionPoint == InjectionPoints.Before) { if (!context.AdviceMethod.ReturnType.IsTypeOf(typeof(void))) { throw new CompilationException("Advice of InjectionPoints." + context.InjectionPoint.ToString() + " can be System.Void only", context.AdviceMethod); } } if (context.InjectionPoint == InjectionPoints.Around) { if ((target & InjectionTargets.Constructor) == InjectionTargets.Constructor) { throw new CompilationException("Advice of InjectionPoints." + context.InjectionPoint.ToString() + " can't be applied to constructors", context.AdviceMethod); } if (!context.AdviceMethod.ReturnType.IsTypeOf(typeof(object))) { throw new CompilationException("Advice of InjectionPoints." + context.InjectionPoint.ToString() + " should return System.Object", context.AdviceMethod); } } }