我在使用反射获取私有方法时遇到问题。即使使用 BindingFlags.NonPublic 和 BindingFlags.Instance 它也不起作用。HandleClientDrivenStatePropertyChanged 定义在与 CreateRadioPropertyInstances 方法相同的类上。
class Program
{
static void Main(string[] args)
{
RadioPropertiesState state = new RadioPropertiesState();
}
}
internal class RadioPropertiesState : BaseRadioPropertiesState
{
}
internal class BaseRadioPropertiesState
{
public BaseRadioPropertiesState()
{
CreateRadioPropertyInstances();
}
private void CreateRadioPropertyInstances()
{
// get the method that is subscribed to the changed event
MethodInfo changedEventHandlerInfo = GetType().GetMethod(
"HandleClientDrivenStatePropertyChanged",
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.IgnoreCase);
}
private void HandleClientDrivenStatePropertyChanged
(object sender, EventArgs e)
{
}
}
GetMethod 返回空值。可能是什么问题?
[编辑代码]