diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index 76b182b..cdf400a 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -335,5 +335,38 @@ namespace ICD.Common.Utils : AssemblyLoadContext.Default.LoadFromAssemblyPath(path); #endif } + + /// + /// Finds the corresponding property info on the given type. + /// + /// + /// + /// + 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); + } } }