Skip to content

Instantly share code, notes, and snippets.

@lasandell
Last active August 29, 2015 13:56
Show Gist options
  • Save lasandell/9230342 to your computer and use it in GitHub Desktop.
Save lasandell/9230342 to your computer and use it in GitHub Desktop.
Comparison of custom log4net Layout class I wrote in C# versus its F# equivalent.
public class GuidLayout : RawPropertyLayout
{
public override object Format(LoggingEvent loggingEvent)
{
var baseFormat = base.Format(loggingEvent);
if (baseFormat is Guid)
return baseFormat;
var guidString = baseFormat as string;
if (guidString != null)
{
Guid guid;
if (Guid.TryParse(guidString, out guid))
return guid;
}
return null;
}
}
type GuidLayout() =
inherit RawPropertyLayout()
override this.Format(loggingEvent) =
match base.Format(loggingEvent) with
| :? Guid as guid -> box guid
| :? string as guidString ->
match Guid.TryParse(guidString) with
| true, guid -> box guid
| _ -> null
| _ -> null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment