My workaround is when binding dgv. I need the base interfaces and the inheriting interfaces to remain in the same structure, simply because I do other things with the width of the final concerete class, not only display the data in the DataGridView. So for example:
interface IGenericPerson { int ID { get; set; } string Name { get; set; } } interface IOperator : IGenericPerson { bool IsAdmin { get; set; } }
specific class:
class Operator : IOperator { public Operator(){} public Operator(int id, string name, bool isAdmin) { this.ID = id; this.Name = name; thsi.IsAdmin = isAdmin; } public int ID { get; set; } public string name { get; set; } public bool IsAdmin { get; set; } }
and in the gateway class:
public IList<IOperator> GetOperators() { IList<IOperator> list = new List<IOperator>(); list.add(new Operator(112, "Mark Twain", false); list.add(new Operator(112, "Charles Manson", false); list.add(new Operator(112, "Richard Nixon", true); return list; }
Now, if I try to bind a datagridView as follows:
Gateway gt = new Gateway(); dgv.DataSource = gt.GetOperators();
I get a DataGridView with only a single IsAdmin bool column from the IOperator interface, not with an identifier, nor with Name attributes from its base interface.
but if I do this:
Gateway gt = new Gateway(); IList<IOperator> list = gt.GetOperators(); IList<Operator> ds = new List<Operator>(); foreach(IOperator op in list) ds.add((Operator)op); dgv.DataSource = ds;
Everything is working correctly.
Thus, I do not need to change the intarfaces chain structure, useful for other purposes, and only when displaying the data I just insert the fragment above.