vb.net:有没有一种方法可以将代码追溯到几个级别? [英] vb.net: Is there a way that we can trace code back to several level up?

查看:80
本文介绍了vb.net:有没有一种方法可以将代码追溯到几个级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们自定义了MessageBox3,其中包含一个用于显示文本的lblMessage.

We have customized MessageBox3 which includes a lblMessage inside to display text.

MessageBox3.Show(ByVal textMsg作为字符串,ByVal标题作为字符串)-共享子,

MessageBox3.Show(ByVal textMsg as string, ByVal caption as string) -- Shared Sub,

在Show()子内部,它将调用MessageBox3 :: New()和lblMessage.Text = textMsg

Inside Show() sub, it will call MessageBox3::New() and lblMessage.Text = textMsg

通常,在调用MessageBox3.Show()时,调用语句如下:

Normally, when calling MessageBox3.Show(), the calling statement as following:   

MessageBox3.Show (resource.GetString("textContents"), resource.GetString("title"))

我们需要做的是来自"lblMessage.Text = textMsg"语句,我们需要回溯以查看传递到textMsg的参数是否为"resource.GetString("textContents"))形式,如果是这样,我们想按以下方式更改代码

what we need to do is from "lblMessage.Text = textMsg" statement, we need to trace back to see if parameter passing into the textMsg is as form "resource.GetString("textContents")", if so, we want to change the code as following

lblMessage.Text = resource.GetString("textContents",lblMessage)

lblMessage.Text = resource.GetString("textContents", lblMessage)

这可以实现吗?我们听到人们提到反射"可以做到吗?

Is this achieveable? We heard people mention about "Reflection" can do this?

如果可以的话,有人可以给我们看代码示例吗?谢谢!

Could anyone show us code example if it is possible? Thx!

JaneC

推荐答案

如果我了解

     在运行方法代码时,您希望使用反射检查传递给该方法的参数.

     while running the code of a method, you want to examine the arguments passed to this method, using reflection.

     然后,如果参数不对应于 ", resource.GetString("textContents",lblMessage)",您要在程序集中发出带有正确参数的动态方法,并调用此方法,... 为了调用带有正确文本内容的MessageBox3.show.

     then, if the arguments do not correspond to  " resource.GetString("textContents", lblMessage)", you want to emit a dynamic method in the assembly, with the right arguments, and invoke this method, ... All this in order to call MessageBox3.show with the right text content.

当然可以,

但是...

 我无法想象没有一个更简单的解决方案,...

   I cant imagine that there is not a simpler solution, ...

--------------------------

--------------------------

在任何情况下,您都可以显示代码吗,如果您想举一个如何发出方法的示例,我们需要看一下它

in any case, can you show your code, If you want an example of how to emit your method, we need to see it

,我们可能还会提供一些更好的选择.

and we may also come with some better alternatives. 


这篇关于vb.net:有没有一种方法可以将代码追溯到几个级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆