public static string GetValueFromProperty(object property)
{
switch (property.GetType().Name)
{
case "String":
return ((String)property);
case "Lookup":
return ((Microsoft.Crm.Sdk.Lookup)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Lookup)property).Value.ToString();
case "Picklist":
return ((Microsoft.Crm.Sdk.Picklist)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Picklist)property).name.ToString();
case "Customer":
return ((Microsoft.Crm.Sdk.Customer)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Customer)property).name.ToString();
case "CrmNumber":
return ((Microsoft.Crm.Sdk.CrmNumber)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmNumber)property).Value.ToString();
case "CrmFloat":
return ((Microsoft.Crm.Sdk.CrmFloat)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmFloat)property).Value.ToString();
case "CrmMoney":
return ((Microsoft.Crm.Sdk.CrmMoney)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmMoney)property).Value.ToString();
case "CrmBoolean":
return ((Microsoft.Crm.Sdk.CrmBoolean)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmBoolean)property).Value ? "1" : "0";
case "CrmDateTime":
return ((Microsoft.Crm.Sdk.CrmDateTime)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmDateTime)property).Value;
case "Status":
return ((Microsoft.Crm.Sdk.Status)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Status)property).Value.ToString();
case "State":
return "0";
case "Key":
return ((Microsoft.Crm.Sdk.Key)property).Value.ToString();
case "Owner":
return ((Microsoft.Crm.Sdk.Owner)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Owner)property).name.ToString();
}
return "";
}
Enjoy,
Rami Heleg