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.
A fluent builder interface for the
MailTemplateclass would look something like this:Usage would look like this:
Another approach would be to use extension methods:
Usage would now look like this:
Please note:
In both cases, the
MailTemplateclass is not polluted with code for this fluent interface. It would be a simple class:So, after you created that instance with any one of the provided fluent interfaces, you can simply read the values by accessing the properties: