mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-10 02:05:20 +00:00
feat: util method for looking up a property on a class via another property info
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user