feat: util method for looking up a property on a class via another property info

This commit is contained in:
Chris Cameron
2018-04-04 16:46:09 -04:00
parent e19a41c7cc
commit 778f28222e

View File

@@ -335,5 +335,38 @@ namespace ICD.Common.Utils
: AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
#endif
}
/// <summary>
/// Finds the corresponding property info on the given type.
/// </summary>
/// <param name="type"></param>
/// <param name="property"></param>
/// <returns></returns>
public static PropertyInfo GetImplementation(Type type, PropertyInfo property)
{
if (type == null)
throw new ArgumentNullException("type");
if (property == null)
throw new ArgumentNullException("property");
if (type.IsInterface)
throw new InvalidOperationException("Type must not be an interface");
property = type
#if SIMPLSHARP
.GetCType()
#else
.GetTypeInfo()
#endif
.GetProperty(property.Name, property.PropertyType);
if (property == null)
return null;
return property.DeclaringType == type
? property
: GetImplementation(property.DeclaringType, property);
}
}
}