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

  • SEARCH
  • Home
  • 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 8951691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:43:21+00:00 2026-06-15T13:43:21+00:00

I never used the fluent code style before. So this is hte first time

  • 0

I never used the fluent code style before. So this is hte first time I tried to develop something in the fluent style with a C# property declaration, but I get an error. Can anyone help me?

public class MailTemplate
{
    string _MailBody = "";
    public MailTemplate MailBody
    {
        get { return _MailBody; }
        set { _MailBody = value ; }
    }

    string _Subject = "";
    public MailTemplate Subject
    {
        get { return _Subject; }
        set { _Subject = value; }
    }

    string _MailFrom = "";
    public MailTemplate MailFrom
    {
        get { return _MailFrom; }
        set { _MailFrom = value; }
    }
}

Please help me how I could assign or initialize the mail body and later also can read with same property name. I think a property cannot be used in case of fluent style development. Need some light here.

  • 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-15T13:43:22+00:00Added an answer on June 15, 2026 at 1:43 pm

    A fluent builder interface for the MailTemplate class would look something like this:

    public class MailTemplateBuilder
    {
        string _body;
        string _subject;
        string _sender;
    
        public MailTemplateBuilder WithBody(string body)
        {
            _body = body;
            return this;
        }
    
        public MailTemplateBuilder WithSubject(string subject)
        {
            _subject = subject;
            return this;
        }
    
        public MailTemplateBuilder WithSender(string sender)
        {
            _sender = sender;
            return this;
        }
    
        public MailTemplate Build()
        {
            return new MailTemplate(_sender, _subject, _body);
        }
    }
    

    Usage would look like this:

    var template = _builder.WithBody("body")
                           .WithSubject("subject")
                           .WithSender("sender")
                           .Build();
    

    Another approach would be to use extension methods:

    public static class MailTemplateBuilder
    {
        public static MailTemplate WithBody(this MailTemplate item, string body)
        {
            item.MailBody = body;
            return item;
        }
    
        public static MailTemplate WithSubject(this MailTemplate item, string subject)
        {
            item.MailSubject = subject;
            return item;
        }
    
        public static MailTemplate WithSender(this MailTemplate item, string sender)
        {
            item.MailFrom = sender;
            return item;
        }
    }
    

    Usage would now look like this:

    var template = new MailTemplate().WithBody("body")
                                     .WithSubject("subject")
                                     .WithSender("sender");
    

    Please note:
    In both cases, the MailTemplate class is not polluted with code for this fluent interface. It would be a simple class:

    public class MailTemplate
    {
        public string MailBody { get; set; } = "";
        public string Subject { get; set; } = "";
        public string MailFrom { get; set; } = "";
    }
    

    So, after you created that instance with any one of the provided fluent interfaces, you can simply read the values by accessing the properties:

    var body = template.MailBody;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I never used fiddler core before. But after first time using it into my
I have never used Foxpro before. Can you convert the following Foxpro code into
I've never used Java AWT before and now I've got a piece of code
So I've never used XSLT before, so this is probably a very simple problem.
I've never used MVVM before, so I'm probably missing something obvious. When I create
I have never used namespaces for my code before. (Other than for using STL
I have never used jQuery before and I'm trying to do something really simple
Never used a cache like this before. The problem is that I want to
Having never used awk before on Linux I am attempting to understand how it
I've never used JSON before so I'm not familiar with its syntax. At the

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.