Skip to content

Instantly share code, notes, and snippets.

View jpolvora's full-sized avatar

Jone jpolvora

View GitHub Profile
@jpolvora
jpolvora / InterceptUsingActionsAndExpressionsToGetMethodNames.cs
Created May 18, 2012 04:22
InterceptUsingActionsAndExpressionsToGetMethodNames
static void InterceptUsingActionsAndExpressionsToGetMethodNames()
{
//pass an array of lambdas to get the names of the methods that will be intercepted
var proxyCtx = ObjectProxyFactory
.CreateUsingActions<IUnitOfWork>(new MyContext(),
pre => System.Console.WriteLine("Entering {0}", pre.CallCtx.MethodName),
pos => System.Console.WriteLine("Exiting {0}", pos.CallCtx.MethodName),
null, true,
//no magic strings
m1 => m1.SaveChanges(),
@jpolvora
jpolvora / InterceptUsingActionsAndStringArrayMethods.cs
Created May 18, 2012 04:27
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();
@jpolvora
jpolvora / InterceptAllMethodsFromInterface.cs
Created May 18, 2012 04:29
InterceptAllMethodsFromInterface
using System;
namespace DynamicProxy.Console.Infra
{
public interface IUnitOfWork : IDisposable
{
int SaveChanges();
}
}
@jpolvora
jpolvora / InterceptWithAttributeEntity.cs
Created May 19, 2012 00:12
InterceptWithAttributeEntity
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Dynamic;
using System.Reflection;
using System.Linq.Expressions;
static void InterceptWithAttributeEntity()
{
var myContext = new MyContext();
@jpolvora
jpolvora / InterceptWithAttributeEntity2.cs
Created May 19, 2012 00:34
InterceptWithAttributeEntity2
public interface INotifyPropertyChangedExtended : INotifyPropertyChanged
{
void OnPropertyChanged(string propertyName);
}
public interface IOrder : INotifyPropertyChangedExtended
{
int Id { get; set; }
ICustomer Customer { get; set; }
}
@jpolvora
jpolvora / NotifyPropertyChangedProxy.cs
Created May 19, 2012 11:31
NotifyPropertyChangedProxy Generic
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Reflection;
namespace DynamicUtils
{
public class NotifyPropertyChangedProxy<T> : DynamicObject, INotifyPropertyChanged
@jpolvora
jpolvora / InterceptingWithDuckTyping.cs
Created May 19, 2012 12:07
InterceptingWithDuckTyping.cs
namespace DynamicProxy.Console
{
class Program
{
static void Main()
{
var myContext = new MyContext();
//create entries in DbContext
Customer entry = myContext.Customers.FirstOrDefault();
public static class CaliburnExtensions
{
public static IEnumerable<IResult> BeginExecute(this IEnumerable<Func<IResult>> routines)
{
return routines.Select(routine => routine());
}
public static void AsCoroutine(this IEnumerable<IResult> routine,
EventHandler<ResultCompletionEventArgs> callBack = null,
ActionExecutionContext ctx = null)
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for FilePicker.xaml
/// </summary>
public partial class FilePicker : UserControl
{
@jpolvora
jpolvora / BusyResultWrapper.cs
Created November 16, 2012 18:29
BusyResultWrapper
//Original Idea: http://blog.smoothfriction.nl/archive/2012/05/07/silverlight-busyindicator-in-caliburn-micro-pt-2-again.aspx
//A simpler solution:
public interface IBusy
{
bool IsBusy { get; set; }
}