0
我写一个使用的Microsoft Dynamics CRM API来用用CRM给出的EntityCollection获取信息的表格的程序。我的问题是,该实体是由KeyValuePair<string, object>
组成,这导致头痛。运行时kvps中的一些对象类型为OptionSetValue
,我需要一种实际访问值的方式,因为OptionSetValue
需要额外的存取器。转换对象类型Microsoft.Xrm.Sdk.OptionSetValue型
下面是一些例子代码来证明我的问题(“E”是实体):
foreach (KeyValuePair<string, object> thePair in e.Attributes.ToList())
{
int theResult = thePair.Value;
}
在上面的例子中,程序将编译,但在运行时将抛出厚望,因为它会尝试从转换OptionSetValue
至int32
。
这是我想以某种方式完成的:
foreach (KeyValuePair<string, object> thePair in e.Attributes.ToList())
{
int theResult = thePair.Value.Value;
}
在这种情况下的.Value
访问将返回我需要的价值,但因为C#编译器不知道thePair
是OptionSetValue
型的,直到运行时,它将不会编译,因为对象类型没有.Value
成员。
任何想法或需要澄清我的问题?