1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.Core/Utilities/ReflectionUtilities.cs
SpoinkyNL c5dbe73000 Profile editor - Continue updating datamodel in editor
Display conditions - Added setting to display current values while selecting condition targets
2020-08-06 22:09:28 +02:00

24 lines
863 B
C#

using System;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.Utilities
{
public static class ReflectionUtilities
{
public static PropertyInfo GetPropertyInfo<TSource, TProperty>(TSource source, Expression<Func<TSource, TProperty>> propertyLambda)
{
var type = typeof(TSource);
var member = propertyLambda.Body as MemberExpression;
if (member == null)
throw new ArgumentException(string.Format("Expression '{0}' refers to a method, not a property.", propertyLambda));
var propInfo = member.Member as PropertyInfo;
if (propInfo == null)
throw new ArgumentException(string.Format("Expression '{0}' refers to a field, not a property.", propertyLambda));
return propInfo;
}
}
}