C# 对象类型末尾的符号和字符是什么?
我不得不反编译一些代码,我不知道这个语法是什么?你们能帮我吗,或者给我写一篇关于它是什么的评论?我用谷歌搜索了这个网站,什么也没找到 只有一行代码:C# 对象类型末尾的符号和字符是什么?,c#,decompiling,reflector,C#,Decompiling,Reflector,我不得不反编译一些代码,我不知道这个语法是什么?你们能帮我吗,或者给我写一篇关于它是什么的评论?我用谷歌搜索了这个网站,什么也没找到 只有一行代码: Rectangle pageBounds; // ISSUE: explicit reference operation // ISSUE: variable of a reference type Rectangle& local = @pageBounds; 矩形对象类型末尾的@符号是什么,以及@变量前面的@是什么 这是我需要修复的最
Rectangle pageBounds;
// ISSUE: explicit reference operation
// ISSUE: variable of a reference type
Rectangle& local = @pageBounds;
矩形对象类型末尾的@
符号是什么,以及@
变量前面的@
是什么
这是我需要修复的最后一行代码,以便再次编译此可执行文件
下面是使用此语法的方法,我可以删除它吗
protected override void OnPrintPage(PrintPageEventArgs e)
{
Application.DoEvents();
++this._pageNum;
float num1;
if (this.Header != null)
{
num1 = this.Header.CalculateHeight(this, e.Graphics);
this.Header.Draw(this, (float) e.MarginBounds.Top, e.Graphics, e.MarginBounds);
}
else
num1 = 0.0f;
float num2;
if (this.Footer != null)
{
num2 = this.Footer.CalculateHeight(this, e.Graphics);
this.Footer.Draw(this, (float) e.MarginBounds.Bottom - num2, e.Graphics, e.MarginBounds);
}
else
num2 = 0.0f;
Rectangle pageBounds;
// ISSUE: explicit reference operation
// ISSUE: variable of a reference type
Rectangle& local = @pageBounds;
int left = e.MarginBounds.Left;
Rectangle marginBounds = e.MarginBounds;
int y = (int) ((double) marginBounds.Top + (double) num1);
marginBounds = e.MarginBounds;
int width = marginBounds.Width;
marginBounds = e.MarginBounds;
int height = (int) ((double) marginBounds.Height - (double) num2 - (double) num1);
// ISSUE: explicit reference operation
local = new Rectangle(left, y, width, height);
float yPos = (float) pageBounds.Top;
bool flag = false;
int num3 = 0;
while (this._printIndex < this._printElements.Count)
{
PrintElement printElement = (PrintElement) this._printElements[this._printIndex];
float num4 = printElement.CalculateHeight(this, e.Graphics);
if ((double) yPos + (double) num4 > (double) pageBounds.Bottom && num3 != 0)
{
flag = true;
break;
}
else
{
printElement.Draw(this, yPos, e.Graphics, pageBounds);
yPos += num4;
++this._printIndex;
++num3;
}
}
e.HasMorePages = flag;
}
PrintPage上受保护的覆盖无效(PrintPageEventArgs e)
{
Application.DoEvents();
++这个;
浮点数m1;
if(this.Header!=null)
{
num1=this.Header.calculatehHeight(this,e.Graphics);
此.标题.绘图(此,(浮动)e.MarginBounds.Top,e.Graphics,e.MarginBounds);
}
其他的
num1=0.0f;
浮点数m2;
如果(this.Footer!=null)
{
num2=this.Footer.calculatehHeight(this,e.Graphics);
this.Footer.Draw(this,(float)e.MarginBounds.Bottom-num2,e.Graphics,e.MarginBounds);
}
其他的
num2=0.0f;
矩形页面边界;
//问题:显式引用操作
//问题:引用类型的变量
矩形和局部=@pageBounds;
int left=e.MarginBounds.left;
矩形边边界=e.边边界;
int y=(int)((双精度)边界顶部+(双精度)num1);
边缘边界=e.边缘边界;
int width=边缘边界宽度;
边缘边界=e.边缘边界;
整数高度=(整数)((双精度)边界高度-(双精度)num2-(双精度)num1);
//问题:显式引用操作
局部=新矩形(左、y、宽、高);
float yPos=(float)pageBounds.Top;
布尔标志=假;
int num3=0;
while(this.\u printIndex(double)pageBounds.Bottom&&num3!=0)
{
flag=true;
打破
}
其他的
{
printElement.Draw(this、yPos、e.Graphics、pageBounds);
yPos+=num4;
++这是.\u printfindex;
++num3;
}
}
e、 HasMorePages=旗帜;
}
参见此处-(但从未使用过)
前缀“@”允许使用关键字作为标识符
,这在与其他编程语言交互时非常有用。字符@实际上不是标识符的一部分,因此该标识符在其他语言中可能被视为普通标识符,没有前缀。带有@前缀的标识符称为逐字标识符。允许对非关键字的标识符使用@前缀,,但强烈反对使用@前缀作为样式
例如:
class @class
{
public static void @static(bool @bool) {
if (@bool)
System.Console.WriteLine("true");
else
System.Console.WriteLine("false");
}
}
class Class1
{
static void M() {
cl\u0061ss.st\u0061tic(true);
}
}
这行代码前面的注释会准确地告诉您发生了什么。类型名称后的&符号表示它是引用类型,变量名称前的@符号生成对该变量的引用
(在C#代码中也可以使用@符号来“转义”关键字以用作变量名,但这里不是这样的情况。“pageBounds”不是C#关键字。)
请注意,这不是有效的C#语法——尽管CLR支持局部变量,但不能引用C#中的局部变量。(注意:从C#7.0开始,这不再是正确的;虽然描述了语法,但它没有使用&
,因此此反编译代码仍然是无效的C#)
例如,当您使用ref
和out
参数时,会隐式地创建对局部变量的引用,但会使用关键字,而不是显式地将参数键入为引用。(例如,如果您有一个out int x
,在内部该变量的类型为Int32&
)如果该代码是合法的C#,则该代码的意图是pageBounds
和local
是具有两个不同名称的同一实例;你对一个人做的任何事都会发生在另一个人身上。例如,这个非法代码:
Rectangle pageBounds;
Rectangle& local = @pageBounds;
local = new Rectangle();
Rectangle pageBounds = new Rectangle();
与本法典相同:
Rectangle pageBounds;
Rectangle& local = @pageBounds;
local = new Rectangle();
Rectangle pageBounds = new Rectangle();
如果您试图以反编译的方式编译代码,您将得到一个错误,因为编译器将&视为按位and,并且会抱怨您使用了一个类型,就好像它是一个变量一样。但这没关系,因为您不是从C#源文件获取的。你反编译了一个IL方法来获得它,你可以在IL中做很多在C#中是非法的事情。当您反编译代码时,这种情况总是发生;例如,您会看到非法的类和方法名称。这只是意味着编译器根据原始代码生成IL,而原始代码不会直接翻译回C#,而是按照您想要的方式运行。您得到的代码很简单,这是反编译器从它拥有的IL生成C#代码的最佳尝试
您可以在大量Jetbrains错误报告中看到生成这些引用的代码类型示例:
阅读参考资料和pointers@MichaelDibbets:这是C#…C#有引用、指针和值类型;)混乱的标题和正文。。。&
是“符号”(title),@
是“在”(body)-“你在问什么?”事实上,两者都是。我应该改变我的头衔…太棒了。谢谢你的解释,现在有点道理了。在我的情况下,要使代码正常工作(并设置矩形x=new Rectangle();)是否像删除这两个额外字符一样简单?老实说,我看不出有任何理由需要local
变量;它仅用于通过引用构造pageBounds
。我怀疑是编译器优化让反编译器感到困惑。只需消除local
,直接构建一个新的pageBounds
。非常感谢Michael!请在表决前写下理由。喝点酒