我想创建一个表单,我可以编辑我的类的字段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;
}
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
但我有这样的错误
可访问性不一致:属性类型"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<AttributeHandler> attributes;
public TagHandler(string tag, bool close)
{
attributes = new List<AttributeHandler>();
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
}
Run Code Online (Sandbox Code Playgroud)
这些是问题:
public TagHandler tag { set; get; }
public EditTag(TagHandler tag)
Run Code Online (Sandbox Code Playgroud)
后者是公共类中的公共方法.因此它的所有参数及其返回类型也应该是公开的 - 否则你会说"你可以调用它,但是你不能知道你用它调用它的类型"(或它返回的内容,如果它是返回的话类型不公开.同样,财产的类型必须是公开的.
将构造函数和属性设置为internal或将TagHandler
类型设置为public.
您应该将TagHandler
类设置为public
public class TagHandler
Run Code Online (Sandbox Code Playgroud)
你可以看看这些问题: