Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpolvora/2723143 to your computer and use it in GitHub Desktop.
Save jpolvora/2723143 to your computer and use it in GitHub Desktop.
InterceptUsingActionsAndStringArrayMethods
static void InterceptUsingActionsAndStringArrayMethods()
{
//helper method that returns the method name - no magic strings
var methods = ObjectProxyFactory.GetMethodNames<IUnitOfWork>(c => c.SaveChanges());
//helper method that returns the method names from the properties (getters and setters) - no magic strings
var methodsFromProperties = ObjectProxyFactory.GetMethodNamesFromProperties<IMyContext>(c => c.Customers);
//union two above arrays
var mixedArray = methods.Union(methodsFromProperties).ToArray();
var proxyCtx = ObjectProxyFactory
.CreateUsingActions<IMyContext>(new MyContext(),
pre =>
{
System.Console.WriteLine("Entering {0}", pre.CallCtx.MethodName);
},
pos =>
{
System.Console.WriteLine("Exiting {0}", pos.CallCtx.MethodName);
}, null, true,
mixedArray); //methods
var customers = proxyCtx.Customers.ToList(); //Customers will be intercepted ( get_Customers )
foreach (var customer in customers)
{
System.Console.WriteLine(customer.Name);
}
proxyCtx.SaveChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment