class - C# - Complex variable-assignment -



class - C# - Complex variable-assignment -

i have class row. class should have content-property. content of type: list<irowcontent>

(irowcontent interface)

other classes column , textcontent, imagecontent implements interface irowcontent.

i can add together columns list or real "content" (text or image).

but can add together columns , text/image. if row contains text/image should not contain item.

how can design class-structure back upwards this?

edit: additionals infos: want build layout "fluent interfaces" http://en.wikipedia.org/wiki/fluent_interface

and idee prevent wrong utilize intellisense of visualstudio.

here classes: layout have column-list.

class layout { //attributes public color background { get; set; } public list<column> columns { get; set; } public uint margin { get; set; } public layout addcolumn(column c) { homecoming null; } public layout setcolumnlist(list<column> c) { homecoming null; } }

the column has list of content (icolumncontent). column irowcontent.

class column : irowcontent { public list<icolumncontent> content { get; private set; } public column addtocontent(icolumncontent obj) { homecoming null; } public column setcontent(list<icolumncontent> objs) { homecoming null; } }

same row irowcontent:

class row : icolumncontent { public list<irowcontent> content { get; private set; } //... }

imagecontent , textcontent implements both interfaces:

class textcontent : irowcontent, icolumncontent class imagecontent : irowcontent, icolumncontent

if declare interface

interface irowcontent { bool supportsotherchildren{ get; } ... } class imagecontent : irowcontent { public bool supportsotherchildren { { homecoming false; } } } class column : irowcontent { public bool supportsotherchildren { { homecoming true; } } }

you can override collection's insert , remove methods back upwards behavior:

class rowcontentcollection : collection<irowcontent> { bool containssingleitem = false; protected override void insertitem(int index, irowcontent item) { if (containssingleitem) throw new invalidoperationexception("collection contains item doesnt allow other items."); containssingleitem = !item.supportsotherchildren; base.insertitem(index, item); } protected override void removeitem(int index) { if (!this[index].supportsotherchildren) containssingleitem = false; base.removeitem(index); } }

c# class list interface

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -