设置参数调用方法

发布于 2024-10-07 21:48:57 字数 567 浏览 0 评论 0原文

我有一个关于.Net CF 3.5 Reflection的问题。我正在调用这样的预期方法,

        object n=  instance.Type.GetMethod("DoSome"
            ).Invoke(instance.Instance,
            new object[] { commandKeys }
            );

commandKey是我的参数列表,instance.Type和instance.Instance不为空。 方法正常调用,但是当我在“DoSome”方法中设置任何属性(属于我调用的类)时,属性没有值(默认值)。

 public class CSet:ITask
{
  public void DoSome
{
   SomeProperty=true;
   OnTaskCompleted(this);


}
}

我正在捕获包含“ITask”接口的“OnTaskCompleted”委托,但就像我说的,ITask SomeProperty 没有我给定的值,

谢谢您的回答。

I have a question about .Net CF 3.5 Reflection.I am invoking expected something method like this,

        object n=  instance.Type.GetMethod("DoSome"
            ).Invoke(instance.Instance,
            new object[] { commandKeys }
            );

commandKey is my parameter list, instance.Type and instance.Instance is not null.
Methods invokes normally but, when I set any property(belongs to which I am calling class) in "DoSome" method, property dont have a value(default value).

 public class CSet:ITask
{
  public void DoSome
{
   SomeProperty=true;
   OnTaskCompleted(this);


}
}

I am catching "OnTaskCompleted" delegate which contains "ITask" interface but like i said ITask SomeProperty has not my given value

Thx your answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぶ宁プ宁ぶ 2024-10-14 21:48:57

您说“方法正常调用”,但同时您声称方法内的代码未执行。您如何知道该方法已被调用?

您确定 instance.Instace 与您检查 SomeProperty 并捕获 OnTaskCompleted 的实例相同吗?

You say that the "Methods invokes normally", but at the same time you claim that the code inside the method is not executed. How do you know that the method is invoked at all?

Are you sure that instance.Instace is the same instance you check SomeProperty on, and catch OnTaskCompleted from?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文