Fluent Refactoring
I have just made the following refactoring, starting from here:
Owner owner = GetAccountOwner();
Lookup to = new Lookup(EntityName.queue, Settings.Default.ControlQueueID);
Lookup from = new Lookup(EntityName.systemuser, owner.Value);
Guid regarding = PostState.new_parentpolicy.Value;
Picklist priority = PickLists.EmailPriority.Type.High;
SendMail(from, to, title, body, owner, regarding, priority);
I moved here:
Owner owner = GetAccountOwner();
Email
.Owner(GetAccountOwner())
.From(EntityName.systemuser, owner.Value)
.To(EntityName.queue, Settings.Default.ControlQueueID)
.Regarding(PostState.new_parentpolicy.Value)
.Priority(PickLists.EmailPriority.Type.High)
.Title(title)
.Body(body)
.Send();
Not much in terms of lines of code, but my sense of aesthetics is pleased, at least. And at least it ensures that we won't have this:
SendMail(
new Lookup(EntityName.systemuser, GetAccountOwner().Value),
new Lookup(EntityName.queue, Settings.Default.ControlQueueID),
title,
body,
GetAccountOwner(),
PostState.new_parentpolicy.Value,
PickLists.EmailPriority.Type.High);