add GetProperty function to return the Property associated with a get_... or set_... special method
This commit is contained in:
parent
8e41ff2f82
commit
2431ffd45a
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user