diff options
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs')
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs b/win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs new file mode 100644 index 000000000..53db9e23f --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Utilities/ExtensionMethods.cs @@ -0,0 +1,35 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace HandBrake.ApplicationServices.Utilities
+{
+ using System.Linq.Expressions;
+ using System.Reflection;
+
+ public static class ExtensionMethods
+ {
+ /// <summary>
+ /// Converts an expression into a <see cref="MemberInfo"/>.
+ /// </summary>
+ /// <param name="expression">The expression to convert.</param>
+ /// <returns>The member info.</returns>
+ public static MemberInfo GetMemberInfo(this Expression expression)
+ {
+ var lambda = (LambdaExpression)expression;
+
+ MemberExpression memberExpression;
+ if (lambda.Body is UnaryExpression)
+ {
+ var unaryExpression = (UnaryExpression)lambda.Body;
+ memberExpression = (MemberExpression)unaryExpression.Operand;
+ }
+ else
+ memberExpression = (MemberExpression)lambda.Body;
+
+ return memberExpression.Member;
+ }
+
+ }
+}
|