Declaring Literal Objects in C#

Here’s an awesome blog post on how to declare literal objects and object arrays in C#.

My example involved calling a method within my C# custom workflow activity class:

protected override void Execute(CodeActivityContext executionContext)
{
.
.
.
    dynamic[] sendFields = {
        new { type = "TO", teamMembers = GetTeamMembers(service, LookupToTeam.Get<EntityReference>(executionContext)) },
        new { type = "CC", teamMembers = GetTeamMembers(service, LookupCcTeam.Get<EntityReference>(executionContext)) },
        new { type = "BCC", teamMembers = GetTeamMembers(service, LookupBccTeam.Get<EntityReference>(executionContext)) },
    };
.
.
.
}

public static List<TeamMembership> GetTeamMembers(IOrganizationService service, EntityReference teamRef)
{
.
.
.
}

I love how it’s so similar to Javascript. I’ve been working on how to send e-mails to team members as well as attaching quotes to those e-mails in custom workflow activities, all of which I will document in a future blog post, so stay tuned.

Please check out Dan’s blog post as he goes more in-depth on the subject and even goes into specifying methods for literal objects. Nice job, Dan!

See newcome.wordpress.com