可访问性不一致:字段类型“TagHandler”比字段“EditTag.tag”更难访问

我想创建一个表单,我可以编辑我的类TagHandler的字段。 所以我决定作为参数传递给表单的构造函数TagHandler tag ,其中tag – 是我想要编辑的标记。 在我的表单中,我有一个字段tag ,我编辑然后获取其数据。 例如,在我的主窗体中,我有一个带有MouseDoubleClick方法的列表框

 void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { int index = listBox1.SelectedIndex; TagHandler tg = listData[index]; EditTag edit = new EditTag(tg); if (edit.ShowDialog() == System.Windows.Forms.DialogResult.OK) { listData[index] = edit.Tag as TagHandler; } } 

EditTag是表格的地方

 public partial class EditTag : Form { public TagHandler tag { set; get; } public EditTag(TagHandler tag) { InitializeComponent(); this.CenterToParent(); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.tag = tag; this.label2.Text = tag.Tag; } private void button1_Click(object sender, EventArgs e) { tag.Data = richTextBox1.Text; this.DialogResult = System.Windows.Forms.DialogResult.OK; } } 

但我有这样的错误

可访问性不一致:属性类型“XmlMissionEditor.TagHandler”的可访问性低于属性“XmlMissionEditor.EditTag.tag”

可访问性不一致:参数类型“XmlMissionEditor.TagHandler”比方法“XmlMissionEditor.EditTag.EditTag(XmlMissionEditor.TagHandler)”更难访问

有什么问题? 我甚至将tag字段设置为public字段,但它仍然显示相同的错误。 我的类TagHandler看起来像这样

 [Serializable] class TagHandler { private string data; private string tag; private Color color; private List attributes; public TagHandler(string tag, bool close) { attributes = new List(); if (close) { string s = "/" + tag; this.tag = s; } else { this.tag = tag; } } public string Tag { get { return tag; } set { tag = value; } } public string Data { get { return data; } set { data = value; } } ...other methods } 

这些是问题:

 public TagHandler tag { set; get; } public EditTag(TagHandler tag) 

后者是公共类中的公共方法。 因此,它的所有参数及其返回类型也应该是公开的 – 否则你会说“你可以调用它,但是你不能知道你用它调用它的类型”(或它返回的是什么,如果它是返回的类型不公开。同样,财产的类型必须是公开的。

要么将构造函数和属性设置为internal,要么将TagHandler类型设置为public。

您应该将TagHandler类设置为public

 public class TagHandler 

你可以看看这些问题:

  • 使用列表的辅助function不一致
  • 可访问性错误C#不一致
  • 可访问性问题不一致