mirror of
https://github.com/FriendshipIsEpic/FiE-Game.git
synced 2024-12-02 01:47:58 +01:00
26 lines
712 B
C#
26 lines
712 B
C#
|
using System;
|
||
|
using System.Linq.Expressions;
|
||
|
using System.Reflection;
|
||
|
|
||
|
namespace UnityStandardAssets.CinematicEffects
|
||
|
{
|
||
|
public static class FieldFinder<T>
|
||
|
{
|
||
|
public static FieldInfo GetField<TValue>(Expression<Func<T, TValue>> selector)
|
||
|
{
|
||
|
Expression body = selector;
|
||
|
if (body is LambdaExpression)
|
||
|
{
|
||
|
body = ((LambdaExpression)body).Body;
|
||
|
}
|
||
|
switch (body.NodeType)
|
||
|
{
|
||
|
case ExpressionType.MemberAccess:
|
||
|
return (FieldInfo)((MemberExpression)body).Member;
|
||
|
default:
|
||
|
throw new InvalidOperationException();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|