add GetProperty function to return the Property associated with a get_... or set_... special method

This commit is contained in:
Michael Becker 2024-07-28 14:32:48 -04:00
parent 8e41ff2f82
commit 2431ffd45a

View File

@ -1,3 +1,5 @@
using System.Reflection;
namespace MBS.Core.Reflection;
public static class TypeExtensions
@ -29,4 +31,18 @@ public static class TypeExtensions
return false;
}
public static PropertyInfo? GetProperty(this MethodBase methodBase)
{
Type declType = methodBase.DeclaringType;
foreach (PropertyInfo pi in declType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (pi.GetMethod == methodBase
|| pi.SetMethod == methodBase)
{
return pi;
}
}
return null;
}
}