C#:可访问性不一致:属性类型 [英] C#: Inconsistent accessibility: property type
问题描述
这有什么错
public partial class MainWindow : Window
{
public ObservableCollection<TabViewModel> Tabs { get; set; }
public ICollectionView TabsViewSource { get; set; }
public int CurrentIndex { get { return TabsViewSource.CurrentPosition; } }
我得到
可访问性不一致:属性类型'System.Collections.ObjectModel.ObservableCollection'比财产TabsRendering.MainWindow.Tabs少访问
Inconsistent accessibility: property type 'System.Collections.ObjectModel.ObservableCollection' is less accessible than property 'TabsRendering.MainWindow.Tabs'
当我改变code到
public partial class MainWindow : Window
{
ObservableCollection<TabViewModel> Tabs { get; set; }
public ICollectionView TabsViewSource { get; set; }
public int CurrentIndex { get { return TabsViewSource.CurrentPosition; } }
它的工作原理。什么错与公共
在的ObservableCollection
推荐答案
请 TabViewModel
A public类型了。
MakeTabViewModel
a public type too.
显然,它不会使一个的公共的上的公共的含-type属性是一个类型是不公开的意义。怎么可能物业present本身外部组件?
Obviously, it doesn't make sense for a public property on a public containing-type to be of a type that is not public. How could the property present itself to external assemblies?
你的第二个样品工作,因为,作为一般规则,不提供访问修饰符意味着的至少适用的修改被选择作为默认的 - 在这种情况下:私人。显然,与声明内部(?)类型的私有财产没有一致性的问题。
Your second sample works because, as a general rule, providing no accessibility modifiers means that the least applicable modifier is chosen as the default - in this case: private. Clearly, there are no consistency issues with declaring a private property of an internal (?) type.
这篇关于C#:可访问性不一致:属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!