Property interceptors in a nested public class will still automatically be discovered and applied to properties in the parent class, so you can do something like the following to lessen Intellisense clutter:
public partial class Employee {
public class NestedPropertyInterceptors {
[BeforeGet(EntityPropertyNames.LastName)]
public static void BeforeGetLastName(IPropertyInterceptorArgs args) {
var emp = args.Instance as Employee;
Console.Writeline("emp:BeforeGetLastName");
}
}
}
You can also define interception methods in a separate class, being sure to provide the TargetType of the interceptor, and then call the DiscoverInterceptorsFromAttributes method of the PropertyInterceptorManager to force discovery, like this:
PropertyInterceptorManager.CurrentInstance.DiscoverInterceptorsFromAttributes(
typeof(EmployeeInterceptorExtensions));
public class EmployeeInterceptorExtensions {
[BeforeSet( Employee.EntityPropertyNames.Country, TargetType=typeof(Employee))]
public static void LowercaseCountry(IPropertyInterceptorArgs<Employee, String> args) {
var country = args.Value;
if (!String.IsNullOrEmpty(country)) {
args.Value = country.ToLower();
}
}
}