Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Dynamics CRM:null值和GetPropertyValue<;T>;()_C#_Dynamics Crm_Dynamics Crm 4_Xrm - Fatal编程技术网

C# Dynamics CRM:null值和GetPropertyValue<;T>;()

C# Dynamics CRM:null值和GetPropertyValue<;T>;(),c#,dynamics-crm,dynamics-crm-4,xrm,C#,Dynamics Crm,Dynamics Crm 4,Xrm,假设我有下面的代码: public class ContactDTO { public string Email {get; set;} public decimal? ExchangeRate {get; set;} } ...... var contacts = crm.GetEntities("contact") var cList = new List<ContactDTO>(); foreach(contact in contacts) { clist.

假设我有下面的代码:

public class ContactDTO
{
   public string Email {get; set;}
   public decimal? ExchangeRate {get; set;}
}
......

var contacts = crm.GetEntities("contact")

var cList = new List<ContactDTO>();
foreach(contact in contacts)
{
  clist.Add(new ContactDTO
    {
      Email = contact.GetPropertyValue<string>("emailaddress1");
      ExchangeRate = contact.GetPropertyValue<decimal>("exchangerate");
    }
}
public class ContactDTO
{
公共字符串电子邮件{get;set;}
公共十进制?交换率{get;set;}
}
......
var contacts=crm.GetEntities(“联系人”)
var cList=新列表();
foreach(触点中的触点)
{
客户添加(新联系人到)
{
Email=contact.GetPropertyValue(“emailaddress1”);
ExchangeRate=contact.GetPropertyValue(“ExchangeRate”);
}
}
在上面的代码中,如果Dynamics中的汇率为null,我将返回十进制的默认值,这不是我想要的(我想知道它是否为null)。如果我使用:

contact.GetPropertyValue<decimal?>("exchangerate")
contact.GetPropertyValue(“exchangerate”)

如果在Dynamics中为null,那么是否应该返回null?我在其他场景中尝试过这种方法,它总是返回值类型的默认值。如何返回null以确保我的dto对象属性为null?

我建议的一种方法是在检查t的GetPropertyValue方法周围编写一个帮助器/包装器返回类型,并确保返回类型是否可为null(如contact.GetPropertyValue(“exchangerate”)),然后如果属性值也为null,则返回null.HTH.:)