常规编译器和重构编译器之间的行为不匹配 [英] Mismatched behaviour between regular compiler and refactoringcompiler

查看:89
本文介绍了常规编译器和重构编译器之间的行为不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

包含的程序编译没有错误,但是当您尝试使用重构工具时会产生错误




J:\ TypeofTest \ TypeofTest1 \Program.cs(3,27):错误CS0246:无法找到类型或

命名空间名称''Bar''(你错过了使用

指令或汇编参考?)


此外,语法荧光笔不会突出显示条形图。在

" typeof(Bar)"作为一个班级。如果我用typeof(Foo.Bar)替换它,

一切都按预期工作。我不明白的是为什么有一个不同的
。是否可以在这样的属性中隐式引用内部
类(在这种情况下,似乎

重构编译器是不正确的)或者实际上是不允许的(在

这个案例肯定是常规编译器应该说些什么)?我是

使用Visual Studio 2005.


使用System.Diagnostics;


[DebuggerTypeProxy(typeof) (酒吧))]

公共课Foo

{

公共级酒吧

{

private Foo m_foo;

public Bar(Foo foo){m_foo = foo; }

}

}


班级课程

{

static void Main(){}

}

The included program compiles without errors, but produces an error
when you attempt to use a refactoring tool:

J:\TypeofTest\TypeofTest1\Program.cs(3,27): error CS0246: The type or
namespace name ''Bar'' could not be found (are you missing a using
directive or an assembly reference?)

In addition, the syntax highlighter doesn''t highlight the "Bar" in
"typeof(Bar)" as a class. If I replace that with "typeof(Foo.Bar)",
everything works as expected. What I don''t understand is why there is
a difference. Should it be possible to implicitly reference an inner
class in an attribute like this (in which case it seems the
refactoring compiler is incorrect) or is it in fact not allowed (in
which case surely the regular compiler should say something)? I''m
using Visual Studio 2005.

using System.Diagnostics;

[DebuggerTypeProxy(typeof(Bar))]
public class Foo
{
public class Bar
{
private Foo m_foo;
public Bar(Foo foo) { m_foo = foo; }
}
}

class Program
{
static void Main() { }
}

推荐答案

我发现了另一个问题。在这个例子派生的代码中,

来自,相当于Bar的私有类。在这种情况下,当我改变b(b)类型(条形码)时到typeof(Foo.Bar),我得到一个新错误(再次,

只来自重构编译器,而不是常规编译器):


J:\ TypeofTest \ TypeofTest1 \Program.cs(3,31):错误CS0122:''Foo.Bar''由于其保护级别而无法访问



这似乎归结为一个问题,即属性构造函数的表达式是否在范围内部或外部进行评估

类。我应该注意到,我在

中使用私有内部类很大一部分因为这里的例子:

http://msdn2.microsoft.com/en-us/library/x810d419.aspx


即便如此,我认为使用私人内部课程而不是内部顶级课程更加清晰,因为真的没有必要使得任何其他代码都可以看到调试内容。


4月29日上午11点44分,Weeble< clockworksa ... @ gmail。编写:
I''ve found a further problem. In the code that this example is derived
from, the equivalent to Bar is a private class. In that case, when I
change "typeof(Bar)" to "typeof(Foo.Bar)", I get a new error (again,
only from the refactoring compiler, not the regular one):

J:\TypeofTest\TypeofTest1\Program.cs(3,31): error CS0122: ''Foo.Bar'' is
inaccessible due to its protection level

It seems it comes down to a question of whether or not the expression
for attribute constructors are evaluated inside or outside the scope
of the class. I should note that I''m using a private inner class in
large part because of this example here:

http://msdn2.microsoft.com/en-us/library/x810d419.aspx

Even so, I think it''s cleaner to use a private inner class rather than
an internal top-level class, because there''s really no need to make
the debug stuff visible to any other code.

On Apr 29, 11:44 am, Weeble <clockworksa...@gmail.comwrote:

包含的程序编译没有错误,但是当你尝试使用重构工具时会产生错误




J:\ TypeofTest \ TypeofTest1 \Program.cs(3,27):错误CS0246:类型或

命名空间名称''Bar''不能找到(你错过了使用

指令或程序集引用吗?)


另外,语法荧光笔没有突出显示条形图。在

" typeof(Bar)"作为一个班级。如果我用typeof(Foo.Bar)替换它,

一切都按预期工作。我不明白的是为什么有一个不同的
。是否可以在这样的属性中隐式引用内部
类(在这种情况下,似乎

重构编译器是不正确的)或者实际上是不允许的(在

这个案例肯定是常规编译器应该说些什么)?我是

使用Visual Studio 2005.


使用System.Diagnostics;


[DebuggerTypeProxy(typeof) (酒吧))]

公共课Foo

{

公共级酒吧

{

private Foo m_foo;

public Bar(Foo foo){m_foo = foo; }

}


}


课程计划

{

static void Main(){}

}
The included program compiles without errors, but produces an error
when you attempt to use a refactoring tool:

J:\TypeofTest\TypeofTest1\Program.cs(3,27): error CS0246: The type or
namespace name ''Bar'' could not be found (are you missing a using
directive or an assembly reference?)

In addition, the syntax highlighter doesn''t highlight the "Bar" in
"typeof(Bar)" as a class. If I replace that with "typeof(Foo.Bar)",
everything works as expected. What I don''t understand is why there is
a difference. Should it be possible to implicitly reference an inner
class in an attribute like this (in which case it seems the
refactoring compiler is incorrect) or is it in fact not allowed (in
which case surely the regular compiler should say something)? I''m
using Visual Studio 2005.

using System.Diagnostics;

[DebuggerTypeProxy(typeof(Bar))]
public class Foo
{
public class Bar
{
private Foo m_foo;
public Bar(Foo foo) { m_foo = foo; }
}

}

class Program
{
static void Main() { }

}


但产生错误
but produces an error

当您尝试使用重构工具时:
when you attempt to use a refactoring tool:



哪个重构工具?代码很好按原样。常规C#...


Marc

Which refactoring tool? The code is fine "as is" for regular C#...

Marc


4月29日下午12:45,Marc Gravell< marc.grav ... @ gmail.comwrote:
On Apr 29, 12:45 pm, Marc Gravell <marc.grav...@gmail.comwrote:

但产生错误

当您尝试使用重构工具:
but produces an error
when you attempt to use a refactoring tool:



哪个重构工具?代码很好按原样。对于普通的C#...


Marc


Which refactoring tool? The code is fine "as is" for regular C#...

Marc



Visual Studio 2005中的任何内置重构工具似乎都可以

对我而言。例如,右键单击程序 (或任何其他

标识符)并选择Refactor-> Rename ...。输出窗口将

切换到显示输出:重构我所描述的错误将会出现在其中的
。正如我所说,另一个症状是语法高亮。

如果我有typeof(Bar)。然后Bar将显示为黑色,而如果我具有typeof(Foo.Bar),则Foo.Bar将显示为黑色。将显示蓝绿色,颜色

表示类的名称。


我安装了Visual Assist X,但我禁用了这些测试。

Any of the built-in refactoring tools in Visual Studio 2005 seem to do
it for me. For example, right-click on "Program" (or any other
identifier) and choose "Refactor->Rename..." The output window will
switch to "Show output from: Refactor" and the error I described will
appear in it. The other symptom is the syntax highlighting, as I said.
If I have "typeof(Bar)" then "Bar" will appear black, whereas if I
have "typeof(Foo.Bar)", the "Foo.Bar" will appear teal, the colour
that indicates the name of a class.

I do have Visual Assist X installed, but I disabled it for these tests.


这篇关于常规编译器和重构编译器之间的行为不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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