Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6133251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:12:14+00:00 2026-05-23T17:12:14+00:00

i have a class Row . This class should have a Content-property. Currently the

  • 0

i have a class Row.
This class should have a Content-property. Currently the content is of type: List<IRowContent>

(IRowContent is a interface)

Other classes Column and TextContent, ImageContent implements the interface IRowContent.

I can add now some Columns to the list or real “content” (Text or a image).

But you can also add columns and text/image. But if a row contains text/image it should not contain another item.

How can i design my class-structure to support this?

Edit: some additionals infos:
I want to build a layout with “fluent interfaces” http://en.wikipedia.org/wiki/Fluent_interface

And my idee is to prevent wrong use by intellisense of VisualStudio.

Here my classes:
The Layout have a 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)
      {
         return null;
      }

      public Layout SetColumnList(List<Column> c)
      {
         return null;
      }
   }

The column has a list of content (IColumnContent). The column itself is from IRowContent.

class Column : IRowContent
   {
      public List<IColumnContent> Content { get; private set; }

      public Column AddToContent(IColumnContent obj)
      {
         return null;
      }

      public Column SetContent(List<IColumnContent> objs)
      {
         return null;
      }
   }

Same for Row with IRowContent:

   class Row : IColumnContent
   {
      public List<IRowContent> Content { get; private set; }

      //...
   }

ImageContent and TextContent implements both interfaces:

class TextContent : IRowContent, IColumnContent

class ImageContent : IRowContent, IColumnContent
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:12:15+00:00Added an answer on May 23, 2026 at 5:12 pm

    If you declare the interface

    interface IRowContent 
    {
        bool SupportsOtherChildren{ get; }
        ...
    }
    
    class ImageContent : IRowContent
    {
        public bool SupportsOtherChildren
        {
            get { return false; }
        }
    }
    
    class Column : IRowContent
    {
        public bool SupportsOtherChildren
        {
            get { return true; }
        }
    }
    

    You can override a collection’s insert and remove methods to support this behavior:

     class RowContentCollection : Collection<IRowContent>
        {
            bool containsSingleItem = false;
            protected override void InsertItem(int index, IRowContent item)
            {
                if (containsSingleItem)
                    throw new InvalidOperationException("Collection contains an item that 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);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the following class implementing a ListSelectionListener interface. This class should listen
I have: class Car {..} class Other{ List<T> GetAll(){..} } I want to do:
I have class method that returns a list of employees that I can iterate
I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter
I have a couple of tables with similar structures like this: <table> <tbody> <tr>content</tr>
I have a Django admin page for a nested category list like this: I
I have a class called SparseMatrix which contain a private vector of type Cell.
I need to create a type at runtime using the TypeBuilder. This type should
I have found this example on StackOverflow: var people = new List<Person> { new
I have this table where I can generate dynamic rows (which has input <type=text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.