public static void EnsureMethodInterceptable(MethodInfo method) { if (!MemberUtilities.IsInterfaceOrVirtualMethod(method)) { throw new InterceptionException($"Interceptor is applied to the method '{method.Name}' of type '{method.DeclaringType}', which is neither virtual method nor interface implementation method."); } }
public IInterceptorRegistry <TInterceptor> ToMethods <TTarget>(int order, params MethodInfo[] methods) { var targetType = typeof(TTarget); if (!targetType.IsPublic && !targetType.IsNestedPublic) { throw new InterceptionException($"The interceptor '{typeof(TInterceptor)}' must not be applied to non-public type {targetType}."); } foreach (var method in methods) { if (!MemberUtilities.IsInterfaceOrVirtualMethod(method)) { throw new InterceptionException($"The interceptor '{typeof(TInterceptor)}' is applied to the method '{method.Name}' of type '{targetType}', which is neither virtual method nor interface implementation method."); } } foreach (var method in methods) { var key = method.MetadataToken; var list = _interceptorAccessors4Method.TryGetValue(key, out var value) ? value : _interceptorAccessors4Method[key] = new List <Func <Sortable <InvokeDelegate> > >(); list.Add(() => new Sortable <InvokeDelegate>(order, _interceptorFatory())); } return(this); }
public IInterceptorRegistry <TInterceptor> ToProperty <TTarget>(int order, Expression <Func <TTarget, object?> > propertyAccessor) { if (propertyAccessor == null) { throw new ArgumentNullException(nameof(propertyAccessor)); } var property = MemberUtilities.GetProperty(propertyAccessor); var method = property.GetMethod; var valid = false; if (method is not null && MemberUtilities.IsInterfaceOrVirtualMethod(method)) { ToMethods <TTarget>(order, method); valid = true; } method = property.SetMethod; if (method is not null && MemberUtilities.IsInterfaceOrVirtualMethod(method)) { ToMethods <TTarget>(order, method); valid = true; } if (!valid) { throw new InterceptionException($"Interceptor is applied to the property '{property.Name}' of type '{typeof(TTarget)}', whose Get/Set methods are not virtual method or interface implementation method."); } return(this); }
public IInterceptorRegistry <TInterceptor> ToMethod <TTarget>(int order, Expression <Action <TTarget> > methodCall) { if (methodCall == null) { throw new ArgumentNullException(nameof(methodCall)); } var method = MemberUtilities.GetMethod(methodCall); return(ToMethods <TTarget>(order, method)); }
public static void EnsurePropertyInterceptable(PropertyInfo property) { var method = property.GetMethod; if (method is not null && MemberUtilities.IsInterfaceOrVirtualMethod(method)) { return; } method = property.SetMethod; if (method is not null && MemberUtilities.IsInterfaceOrVirtualMethod(method)) { return; } throw new InterceptionException($"Interceptor is applied to the property '{property.Name}' of type '{property.DeclaringType}', whose Get/Set methods are not virtual method or interface implementation method."); }
public IInterceptorRegistry <TInterceptor> ToSetMethod <TTarget>(int order, Expression <Func <TTarget, object?> > propertyAccessor) { if (propertyAccessor == null) { throw new ArgumentNullException(nameof(propertyAccessor)); } var property = MemberUtilities.GetProperty(propertyAccessor); var setMethod = property.SetMethod; if (setMethod is null) { throw new InterceptionException($"Specified property '{property.Name}' of '{property.DeclaringType}' does not have Set method."); } return(ToMethods <TTarget>(order, setMethod)); }