可访问性不一致错误 [英] Inconsistent Accessibility error
问题描述
我试图从升级Visual Studio 2005的ASP.Net应用程序到2008年,我试图编译只是为了验证它会编译和我收到此错误。
I tried upgrading an ASP.Net application from Visual Studio 2005 to 2008, and I tried compiling just to verify that it would compile and I received this error.
Error 1 Inconsistent accessibility: property type 'Web.Properties.UITitleSettings' is less accessible than property 'Web.Ctrl.BasePanel.UISettings' \\projectLocation\Ctrl\BasePanel.cs 25 43 ProjectName
(我删除Web.Properties前的类路径和Web.Ctrl,它通常包含它)
(I removed the class path before Web.Properties and Web.Ctrl, it normally contains it)
的一段代码的引用是
public Properties.UITitleSettings UISettings
{
get
{
return _uiSettings;
}
}
我不太清楚这是什么错误尝试说了。请问类型需要被铸造(无效的隐式转换两个不兼容的类型之间?),或者是一类覆盖问题?
I'm not quite sure what this error is attempting to say. Does the type need to be casted (invalid implicit cast between two incompatible types?) or is it a class override issue?
推荐答案
请看下面的定义。通知富
是任何人都可见的,它的公共方法 GetBar
也可见于任何人谁可以看到富
:
Look at the following definition. Notice Foo
is visible to anyone, and its public method GetBar
is also visible to anyone who can see Foo
:
public class Foo
{
public Bar GetBar() { return new Bar(); }
}
下面的栏定义
:
internal class Bar {}
通知酒吧
是内部装配的,而富
是大家有目共睹的。 富
不能暴露酒吧
到外面的世界,所以编译器将引发此异常。
Notice Bar
is internal to the assembly, whereas Foo
is visible to all. Foo
cannot expose Bar
to the outside world, so the compiler throws this exception.
另一个例子是:
public class Foo
{
public Foo.Bar GetBar() { return new Bar(); }
private class Bar {}
}
酒吧
是富
的私有类的,只能是可见的富<实例/ code>。
富
不能公开此类型到外面的世界,所以编译器会引发同样的异常。
Bar
is a private class of Foo
and can only be visible to instances of Foo
. Foo
cannot expose this type to the outside world, so the compiler throws the same exception.
重构的例子:
-
请了隐藏式的公共
Make the hidden type public
public class Bar {}
public class Foo { public class Bar {} }
封装
Encapsulation
public class BarEncapsulator
{
private Bar _bar;
internal BarEncapsulator(Bar myBar) { _bar = myBar; }
public string BarString { get { return _bar.MyString; } }
}
隐藏一切
Hide everything
internal class Bar {}
internal class Foo { public class Bar {} }
重构它扔掉。
Refactor it away
public class BarEncapsulator
{
private string _barString;
public string BarString { get { return _barString; } }
}
这篇关于可访问性不一致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!