Hi there I got a problem with my application.
I created a new UserControl called EntityOverviewPanel to show information about another class Entity visually.
In order to create an instance of this UserControl I would like to pass an instance of Entity in order to initialize the panel with all data.
public partial class EntityOverviewPanel : UserControl
{
private Entity entity;
public EntityOverviewPanel()
{
InitializeComponent();
}
public void setEntity(Entity e)
{
entity = e;
updatePanel();
}
private void updatePanel()
{
//update panel
}
}
If I try to execute this I get the error mentioned in the title:
Inconsistent accessibility: parameter type 'IFCS.Entity' is less accessible than method 'IFCS.EntityOverviewPanel.setEntity(IFCS.Entity)'
My Entity looks like this (only a part of the class because of its size^^)
class Entity
{
public enum Gender
{
MALE, FEMALE
}
private int id;
private Gender gender;
private string surname, forename;
private Group group;
private Organisation organisation;
private Station station;
private string uid;
public Entity(string surname, Gender gender, Group group, Role role, string forename = "")
{
//code
}
//more code
}
I read about changing class Entity to public class Entity would fix this problem but instead of doing that it just creates a whole bunch of new errors relating to other uses of Entity (with the same error message like in the title).
Any idea on how to fix this?
Thanks in advance 🙂
Well yes – either you need to make
Entitypublic, or yoursetEntitymethod (which sounds like you’re writing Java rather than C#) internal. ChangingEntityOverviewPanelto be internal would fix it too, IIRC.Fundamentally you can’t have a public method in a public class with a parameter or return type which is internal. It doesn’t make any sense to do so.
If making
Entitypublic causes further problems, that’s probably just because you need to do the same thing with other types. You really need to work out whether you do wantEntityand its associated types to be public or not. If you don’t want it to be public, why do you wantsetEntityto be public?