[英]Why is the constructor of a generic class with a default-valued enum parameter not able to call protected methods of that class?
A simple test case: 一个简单的测试用例:
using System;
public class Test<T>
{
public enum TestEnum
{
A,
B
}
public Test (TestEnum a = TestEnum.A)
{
DoSomething ();
}
protected void DoSomething()
{
}
}
The compiler (this is using Mono in a Unity3D project, .NET4.0 target) gives an error on the call in Test()
to DoSomething()
. 编译器(这是在Unity3D项目中使用Mono,.NET4.0目标)在
Test()
调用DoSomething()
出错。 If I remove the default parameter on TestEnum a
, it builds just fine. 如果我删除
TestEnum a
上的默认参数,它就构建得很好。 MonoDevelop wants to call the default parameter TestEnum<>.A
, but that doesn't compile, neither does TestEnum<T>.A
(obviously I wouldn't have expected these to work but using MonoDevelop's autocomplete that's what I get). MonoDevelop想要调用默认参数
TestEnum<>.A
,但是这不能编译, TestEnum<T>.A
(显然我不会期望这些工作,但使用MonoDevelop的自动完成,这是我得到的)。
EDIT: the specific error is: the name DoSomething doesn't exists in the current context
编辑:具体错误是:
the name DoSomething doesn't exists in the current context
As said so in the comments, this is a compiler bug. 正如评论中所说,这是一个编译器错误。
It seems as your Mono development environment doesn't really like the protected keyword. 看起来你的Mono开发环境并不像受保护的关键字那样。
Use {public,private} for now. 立即使用{public,private}。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.