Created
May 18, 2012 04:27
-
-
Save jpolvora/2723143 to your computer and use it in GitHub Desktop.
InterceptUsingActionsAndStringArrayMethods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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