Skip to content

Instantly share code, notes, and snippets.

@bsommardahl
Created December 6, 2012 20:59
Show Gist options
  • Save bsommardahl/4228301 to your computer and use it in GitHub Desktop.
Save bsommardahl/4228301 to your computer and use it in GitHub Desktop.
public interface IObjectPropertyChangerActor<out T>
{
IObjectPropertyChangerActor<T> With(Action<T> action);
IObjectPropertyChangerActor<T> And(Action<T> action);
}
public class ObjectPropertyChangerActor<T> : IObjectPropertyChangerActor<T>
{
readonly T _objectToChange;
public ObjectPropertyChangerActor(T objectToChange)
{
_objectToChange = objectToChange;
}
#region IObjectPropertyChangerActor<T> Members
public IObjectPropertyChangerActor<T> With(Action<T> action)
{
return MakeTheChange(action);
}
public IObjectPropertyChangerActor<T> And(Action<T> action)
{
return MakeTheChange(action);
}
#endregion
IObjectPropertyChangerActor<T> MakeTheChange(Action<T> action)
{
action.Invoke(_objectToChange);
return this;
}
}
public static class ObjectChangingExtensions
{
public static IObjectPropertyChangerActor<T> Change<T>(this T objectToChange)
{
return new ObjectPropertyChangerActor<T>(objectToChange);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment