Skip to content

Instantly share code, notes, and snippets.

@peta
Created April 24, 2018 15:09
Show Gist options
  • Save peta/5e95d4b05064e101daa47f264a3668b1 to your computer and use it in GitHub Desktop.
Save peta/5e95d4b05064e101daa47f264a3668b1 to your computer and use it in GitHub Desktop.
using Microsoft.Xrm.Sdk;
namespace Foo.CRM.Integration.Data.Helper
{
public static class XrmSdkExtensions
{
/// <summary>
/// Retrieve formatted value for given key and optionally return default value when key was not found in collection. This method will
/// not yield any exceptions when a requested key was not found.
/// </summary>
/// <param name="collection"></param>
/// <param name="key" type="string"></param>
/// <param name="defaultValue" type="string"></param>
/// <returns></returns>
public static string GetValue(this FormattedValueCollection collection, string key, string defaultValue = default(string))
{
string value;
return collection.TryGetValue(key, out value) ? value : defaultValue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment