可访问性不一致,属性类型 [英] Inconsistent accessibility, property type
问题描述
我知道在Stack Overflow上有很多与此相关的问题,所以我不会问这些问题是否真的对我有用。以下是我研究过的一些问题:
I know there are many questions answered on Stack Overflow about this, so I wouldn't be asking this question if these solutions actually worked for me. Here are some of the questions I've looked at:
根据上述问题的每种解决方案,我都将我所有的类都指定为公共类我仍然遇到相同的错误。这是我的代码:
I've specified all of my classes as being public, as per each solution to the above questions, but I'm still getting the same error. Here is my code:
namespace TestResourceManager
{
public class ViewModel
{
private List<string> m_ViewOptions = null;
private List<MachineRow> m_ViewChoices = null;
public ViewModel()
{
m_ViewOptions = new List<string>();
m_ViewOptions.Add("item1");
m_ViewOptions.Add("item2");
m_ViewChoices.Add(new MachineRow("machinename1", "builddefinition1", "description1", "envname1", "envtype1"));
m_ViewChoices.Add(new MachineRow("machinename2", "builddefinition2", "description2", "envname2", "envtype2"));
}
public List<string> ViewOptions
{
get { return m_ViewOptions; }
}
public List<MachineRow> ViewChoices
{
get { return m_ViewChoices; }
}
}
public class MachineRow
{
private string MachineName, BuildDefinition, Description, EnvName, EnvType;
public MachineRow(string _MachineName, string _BuildDefinition, string _Description, string _EnvName, string _EnvType)
{
this.MachineName = _MachineName;
this.BuildDefinition = _BuildDefinition;
this.Description = _Description;
this.EnvName = _EnvName;
this.EnvType = _EnvType;
}
}
}
此错误:
Inconsistent accessibility: property type 'System.Collections.Generic.List<TestResourceManager.ViewModel.MachineRow>' is less accessible than property 'TestResourceManager.ViewModel.ViewChoices'
在此行上发生:
public List<MachineRow> ViewChoices
有人知道为什么其他人的解决方案都不适合我的情况吗?
Does anyone know why everyone else's solutions aren't working for my case? Any help much appreciated!
推荐答案
所粘贴的代码不是完整的代码。给定错误消息: System.Collections.Generic.List< TestResourceManager。** ViewModel **。MachineRow>
,问题是存在一个额外的内部类类MachineRow
定义在 ViewModel
类内部的某个位置。
The code, as pasted, is not the complete code. Given the error message: System.Collections.Generic.List<TestResourceManager.**ViewModel**.MachineRow>
, the issue is that there is an extra inner class, class MachineRow
defined somewhere inside of your ViewModel
class.
public class ViewModel
{
// Somewhere before the closing brace, you're defining a MachineRow class that is not public, ie:
class MachineRow {}
这篇关于可访问性不一致,属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!