I want to create a form where I can edit a field of my class TagHandler
.
So I decided to pass as a paramter to form's constructor TagHandler tag
where tag
– is a tag I want to edit. In my form I've got a field tag
which I edit and then get its data.
For example in my main form I've got a listbox with MouseDoubleClick
method
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;
}
}
Where EditTag
is a form
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;
}
}
But I've got such errors
Inconsistent accessibility: property type 'XmlMissionEditor.TagHandler' is less accessible than property 'XmlMissionEditor.EditTag.tag'
Inconsistent accessibility: parameter type 'XmlMissionEditor.TagHandler' is less accessible than method 'XmlMissionEditor.EditTag.EditTag(XmlMissionEditor.TagHandler)'
What's the problem? I even set tag
field as public
but it still shows the same error.
My class TagHandler
looks like this
[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
}
Best Answer
These are the problem:
The latter is a public method in a public class. Therefore all its parameters and its return type should be public too - otherwise you're saying "You can call this, but you can't know about the type you're calling it with" (or what it's returning, if it's the return type that's not public. Likewise the type of the property has to be public.
Either make the constructor and property internal or make the
TagHandler
type public.