奇怪的编译器行为......? [英] Weird compiler behaviour...?
问题描述
所以我有一个非常奇怪的问题......我正在开发一个项目,它会做一些 Reflection
的东西。它所做的一件事是阅读方法的名称。我有代码,实质上看起来如下。
So I''m having a very weird problem... I''m working on a project which does some Reflection
stuff. One of the things it does is read the name of methods. I''ve got code that, in essence, looks like the following.
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Something(AddressOf Test)
End Sub
Private Sub Test()
End Sub
Private Sub Something(ByVal a As Action)
Dim name As String = a.Method.Name
End Sub
End Class
所以在 Something
中你会期望 name
要测试
,对吧?正确。除了在项目中,我正在处理它的'code> __ lambda_1 或者什么......我在互联网上查找了一些C#示例。在C#中尝试了这段代码并且它有效。然后在另一个VB项目中尝试了它,它工作。在另一台机器上尝试它并且它有效...为什么这个项目将我的命名方法编译成匿名方法?事实上,这个项目似乎编译了我用于匿名方法的每个委托
。
如果编译器随机决定创建各种''lambda ''我显然不能用这个......
有什么想法吗?谢谢。
So in Something
you would expect the name
to be Test
, right? Correct. Except that in the project I''m currently working on it''s __lambda_1
or something... I looked it up on the internet and found some C# examples. Tried this code in C# and it worked. Then tried it in another VB project and it worked. Tried it on another machine and it worked... Why the hell does this one project compile my named method into an anonymous one? In fact it seems this project compiles every delegate
I use into an anonymous method.
If the compiler randomly decides to create all kinds of ''lambda'' stuff I obviously can''t use this...
Any ideas? Thanks.
推荐答案
发表评论:
检查是否设置了优化代码你的项目。
Posted from the comment:
Check if the "optimize code" is set in your project.
这篇关于奇怪的编译器行为......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!