blob: 53db9e23f87202a498e608545faa893a6ad31707 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}
}
}
|