Skip to content

Instantly share code, notes, and snippets.

@mavnn
Created May 28, 2011 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavnn/996859 to your computer and use it in GitHub Desktop.
Save mavnn/996859 to your computer and use it in GitHub Desktop.
Sanity inducing extensions for Dynamics CRM 4.0
public static class DynamicEntityExtensions
{
public static string GetString(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property))
return (string)entity[property];
else
return null;
}
public static DateTime? GetDateTime(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property) && !((CrmDateTime)entity[property]).IsNull)
return ((CrmDateTime)entity[property]).UserTime;
else
return null;
}
public static int? GetInt(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property) && !((CrmNumber)entity[property]).IsNull)
return ((CrmNumber)entity[property]).Value;
else
return null;
}
public static double? GetDouble(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property) && !((CrmDouble)entity[property]).IsNull)
return ((CrmDouble)entity[property]).Value;
else
return null;
}
public static decimal? GetMoney(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property) && !((CrmMoney)entity[property]).IsNull)
return ((CrmMoney)entity[property]).Value;
else
return null;
}
public static Key GetKey(this DynamicEntity entity, string property)
{
return (Key)entity[property];
}
public static bool? GetBoolean(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property) && !((CrmBoolean)entity[property]).IsNull)
return ((CrmBoolean)entity[property]).Value;
else
return null;
}
public static Lookup GetLookup(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property) && !((Lookup)entity[property]).IsNull)
return (Lookup)entity[property];
else
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment