Created
July 4, 2014 21:47
-
-
Save einarwh/d223b05e18ce8d0c07eb to your computer and use it in GitHub Desktop.
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
public static class AspectExtensions { | |
public static Func<T> Before<T>(this Func<T> f, Action a) { | |
return () => { a(); return f(); }; | |
} | |
public static Func<T> Success<T>(this Func<T> f, Action a) { | |
return () => { | |
var result = f(); | |
a(); | |
return result; | |
}; | |
} | |
public static Func<T> Success<T>(this Func<T> f, Action<T> a) { | |
return () => { | |
var result = f(); | |
a(result); | |
return result; | |
}; | |
} | |
public static Func<T> After<T>(this Func<T> f, Action a) { | |
return () => { | |
try { | |
return f(); | |
} finally { | |
a(); | |
} | |
}; | |
} | |
public static Func<T> After<T>(this Func<T> f, Action<T> a) { | |
return () => { | |
T result = default(T); | |
try { | |
result = f(); | |
return result; | |
} finally { | |
a(result); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment