Created
May 28, 2011 13:27
-
-
Save mavnn/996859 to your computer and use it in GitHub Desktop.
Sanity inducing extensions for Dynamics CRM 4.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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