Skip to content

Instantly share code, notes, and snippets.

@TeaDrivenDev
TeaDrivenDev / Csharp_vs_Fsharp.md
Last active January 4, 2016 10:09
Comparison of a small MSCRM plugin implemented in C# and F#

As requested by several people on Twitter after I mentioned that the C# implementation is 27 lines, and the F# version saves only two lines over this (which is mainly because there isn't much to save at all). In the mean time, I actually managed to shave off two more lines because the last method call incidentally returns void.

Please note that the plugin as such is not very useful; I'm mainly trying to get an F# plugin to run within MSCRM in the first place.

C#:

	using Microsoft.Xrm.Sdk;
	using System;
	
@TeaDrivenDev
TeaDrivenDev / NestedLets.fs
Created March 11, 2014 21:25
F# composition root with lots of single and with nested lets
// old
let ComposeSimple serviceProvider configuration =
let (context, organizationService, _, _) = DecomposeServiceProvider serviceProvider
let configurationXml = XElement.Parse configuration
let getRecordName = GetRecordName organizationService
let regardingLookups() = ConfiguredRegardingLookups configurationXml
let listFindingRegardingObject() = ListFindingRegardingObject regardingLookups (GetFullRecordImage(context))
let regardingObject = NameAddedRegardingObject getRecordName listFindingRegardingObject
// This....
QueryByAttribute qba = new QueryByAttribute("entityName")
{
ColumnSet = new ColumnSet("fieldA", "fieldB")
};
// There may be several of these lines
qba.AddAttributeValue("fieldC", "fieldCValue");