【问题标题】:Inconsistent accessibility, property type可访问性、属性类型不一致
【发布时间】:2013-07-20 00:01:22
【问题描述】:

我知道 Stack Overflow 上有很多关于这个问题的答案,所以如果这些解决方案真的对我有用,我就不会问这个问题。以下是我研究过的一些问题:

Inconsistent accessibility error C#

Inconsistent accessibility: property type

根据上述问题的每个解决方案,我已将我的所有课程都指定为公开课程,但我仍然遇到同样的错误。这是我的代码:

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

有谁知道为什么其他人的解决方案对我的情况不起作用?非常感谢任何帮助!

【问题讨论】:

  • 代码在我的机器上编译没有任何问题。您是否尝试过重建或清理/构建?
  • 对我来说似乎很好 +1 用于清理/重建。也许值得右键单击MachineRow 并导航到定义,如果它有一些阐明的机会(如果有冲突的定义是罪魁祸首)。
  • 这不是完整的代码 - 错误消息是说 ViewModel 内部有一个名为 MachineRow 的内部类
  • @Pierre-LucPineault 我没有尝试过,我为不尝试而感到愚蠢。当我回到我的电脑前我会尝试并报告。
  • 编辑:在@ReedCopsey 的回答上发表此评论...

标签: c# compiler-errors


【解决方案1】:

粘贴的代码不是完整的代码。鉴于错误消息:System.Collections.Generic.List&lt;TestResourceManager.**ViewModel**.MachineRow&gt;,问题是有一个额外的内部类,class MachineRow 定义在您的 ViewModel 类内部的某处。

public class ViewModel
{
   // Somewhere before the closing brace, you're defining a MachineRow class that is not public, ie:
   class MachineRow {}

【讨论】:

  • MachineView 在我的代码中直接定义在 ViewModel 下方
  • @t3hclwn 确保ViewModel 的右大括号在MachineRow 的声明之前
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-19
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多