Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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