public void Intercept(IInvocation invocation) { // you of course can go way fancier than that. // one thing of note here is that your Property setters would be prefixed with "set_", but nothing stops you from targeting other methods as well var prop = invocation.TargetType.GetProperties() .FirstOrDefault(p => invocation.Method.Name == $"set_{p.Name}" && p.GetCustomAttribute(typeof(EscapeInvalidAttribute)) != null); if (prop != null) { invocation.Arguments[0] = EscapeInvalidAttribute.Escape((string)invocation.Arguments[0]); } invocation.Proceed(); // allow the call to proceed anyway }
public void Intercept(IInvocation invocation) { invocation.Arguments[0] = EscapeInvalidAttribute.Escape((string)invocation.Arguments[0]); invocation.Proceed(); // allow the call to proceed anyway }