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 7736135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:40:15+00:00 2026-06-01T07:40:15+00:00

I have a custom class that I use to build table strings. I would

  • 0

I have a custom class that I use to build table strings. I would like to rewrite the code so that I can chain the operators. Something like:

myObject
  .addTableCellwithCheckbox("chkIsStudent", isUnchecked, isWithoutLabel)
  .addTableCellwithTextbox("tbStudentName", isEditable) etc.

So it seems like I would have each of these methods(functions) return the object itself so that I can then call another method(function) on the resulting object, but I can’t figure out how to get a c# class to refer to itself.

Any help?

  • 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-06-01T07:40:16+00:00Added an answer on June 1, 2026 at 7:40 am

    So you would create a fluent interface like this:

    class FluentTable 
    {
      //as a dumb example I'm using a list
      //use whatever structure you need to store your items
      List<string> myTables = new List<string>();
    
      public FluentTable addTableCellwithCheckbox(string chk, bool isUnchecked, 
                                                            bool  isWithoutLabel)
      {
        this.myTables.Add(chk);
        //store other properties somewhere
        return this;
      }
    
      public FluentTable addTableCellwithTextbox(string name, bool isEditable)
      {
        this.myTables.Add(name);
        //store other properties somewhere
        return this;
      }
      public static FluentTable New()
      {
        return new FluentTable();
      }
    }
    

    Now you could use it like this:

      FluentTable tbl = FluentTable
                        .New()
                        .addTableCellwithCheckbox("chkIsStudent", true, false)
                        .addTableCellwithTextbox("tbStudentName", false);
    

    This should give you a basic idea of how you need to go about it. See fluent interfaces on wikipedia.

    A more correct way to do it would be to implement a fluent interface:

    interface IFluentTable
    {
     IFluentTable addTableCellwithCheckbox(string chk, bool isUnchecked, 
                                                            bool  isWithoutLabel)
     IFluentTable addTableCellwithTextbox(string name, bool isEditable)
     //maybe you could add the static factory method New() here also 
    }
    

    And then implement it : class FluentTable : IFluentTable {}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class that uses boost mutexes and locks like this (only
I have a custom class that has as an instance variable of a coordinate:
I have a custom ButtonUI class that paints the button. Before drawing the text,
I have a custom iterator template class that wraps up a std::list iterator. In
I have created a custom collection class that I am trying to bind to
I have a listbox that displays Shipment Items (custom class) that are formatted using
Here is my custom class that I have that represents a triangle. I'm trying
i'm missing something fundamental here. i have a very simple custom class that draws
I have a custom validator in a domain class that refers to a config
I have a folder with many LaTeX files that all use the same custom

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.