Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.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# 将对象类型转换为Microsoft.Xrm.Sdk.OptionSetValue类型_C#_Dynamics Crm_Crm - Fatal编程技术网

C# 将对象类型转换为Microsoft.Xrm.Sdk.OptionSetValue类型

C# 将对象类型转换为Microsoft.Xrm.Sdk.OptionSetValue类型,c#,dynamics-crm,crm,C#,Dynamics Crm,Crm,我正在编写一个程序,它使用Microsoft Dynamics CRM API用从CRM提供的EntityCollection中获得的信息填充表单。我的问题是实体由KeyValuePair组成,这让人头疼。kvps中的一些对象在运行时属于OptionSetValue类型,我需要一种实际访问该值的方法,因为OptionSetValue需要额外的访问器 下面是一些示例代码来演示我的问题(“e”是实体): 在这种情况下,.Value访问器将返回我需要的值,但由于C编译器在运行时之前不知道thePair

我正在编写一个程序,它使用Microsoft Dynamics CRM API用从CRM提供的EntityCollection中获得的信息填充表单。我的问题是实体由
KeyValuePair
组成,这让人头疼。kvps中的一些对象在运行时属于
OptionSetValue
类型,我需要一种实际访问该值的方法,因为
OptionSetValue
需要额外的访问器

下面是一些示例代码来演示我的问题(“e”是实体):

在这种情况下,
.Value
访问器将返回我需要的值,但由于C编译器在运行时之前不知道
thePair
的类型是
OptionSetValue
,因此它不会编译,因为对象类型没有
.Value
成员


对我的问题有什么想法或需要澄清的吗?

似乎键入这些都给了我一些清晰,因为我在这篇文章发表后不到5分钟就解决了这个问题。您可以简单地使用(OptionSetValue)进行类型转换

foreach(e.Attributes.ToList()中的KeyValuePair)
{
int theResult=(OptionSetValue)thePair.Value.Value;
}
foreach (KeyValuePair<string, object> thePair in e.Attributes.ToList())
{
    int theResult = thePair.Value;
}
foreach (KeyValuePair<string, object> thePair in e.Attributes.ToList())
{
    int theResult = thePair.Value.Value;
}
foreach (KeyValuePair<string, object> thePair in e.Attributes.ToList())
{
    int theResult = (OptionSetValue)thePair.Value.Value;
}