Created
July 4, 2012 20:50
-
-
Save jeremiahredekop/3049473 to your computer and use it in GitHub Desktop.
Revisions
-
jeremiahredekop created this gist
Jul 4, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ public MethodInfo GetMethodInfo<TSource>(Expression<Action<TSource>> methodLambda) { Type type = typeof(TSource); var member = methodLambda.Body as MethodCallExpression; if (member == null) throw new ArgumentException(string.Format( "Expression '{0}' does not refer to a method.", methodLambda)); var methodInfo = member.Method as MethodInfo; if (methodInfo == null) throw new ArgumentException(string.Format( "Expression '{0}' does not refer to a method.", methodLambda)); if (type != methodInfo.ReflectedType && !type.IsSubclassOf(methodInfo.ReflectedType)) throw new ArgumentException(string.Format( "Expresion '{0}' refers to a method that is not from type {1}.", methodLambda, type)); return methodInfo; }