c# - CRM 2011 使用 ICodeWriterFilterService 生成的代码无法构建

标签 c# dynamics-crm dynamics-crm-2011 xrm

使用 http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html 处的示例代码我对此进行了更改,以便 GenerateEntity 和 GenerateOptionSet 具有代码:

return optionSetMetadata.Name.ToLowerInvariant().StartsWith("myprefix");

这会生成类型,包括选项集的一些枚举。然而,实体中选项集的实际实现并没有使用它,但我得到以下信息:

    [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("myprefix_fieldname")]
    public Microsoft.Xrm.Sdk.OptionSetValue myprefix_FieldName
    {
        get
        {
            Microsoft.Xrm.Sdk.OptionSetValue optionSet = this.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>("myprefix_fieldname");
            if ((optionSet != null))
            {
                return ((Microsoft.Xrm.Sdk.OptionSetValue)(System.Enum.ToObject(typeof(Microsoft.Xrm.Sdk.OptionSetValue), optionSet.Value)));
            }
            else
            {
                return null;
            }
        }
        set
        {
            this.OnPropertyChanging("myprefix_FieldName");
            if ((value == null))
            {
                this.SetAttributeValue("myprefix_fieldname", null);
            }
            else
            {
                this.SetAttributeValue("myprefix_fieldname", new Microsoft.Xrm.Sdk.OptionSetValue(((int)(value))));
            }
            this.OnPropertyChanged("myprefix_FieldName");
        }
    }

显然,在 setter 中将 OptionSetValue 转换为 int 不会编译,我假设它应该生成类型与生成的枚举匹配的属性,但事实并非如此。我需要做什么来纠正这个问题?

最佳答案

看起来 crmsrvcutil 中有一个错误,此错误已被修复。我的 OptionSet 属性代码现在如下所示:

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("prioritycode")]
public Microsoft.Xrm.Sdk.OptionSetValue PriorityCode
{
    get
    {
        return this.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>("prioritycode");
    }
    set
    {
        this.OnPropertyChanging("PriorityCode");
        this.SetAttributeValue("prioritycode", value);
        this.OnPropertyChanged("PriorityCode");
    }
}

我在设置 OptionSetValue 时没有出错...

关于c# - CRM 2011 使用 ICodeWriterFilterService 生成的代码无法构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8443981/

相关文章:

C# 如何创建 while 循环来验证对象是否为 null

c# - 将 .NetStandard 2.0 Nuget 包安装到 VS2015 Net 4.6.1 项目中

c# - 如何获取 MSMQ 队列中的所有可用消息

dynamics-crm - 使用模板创建电子邮件,然后附加动态附件

javascript - 从js中获取createby属性值

c# - GeckoFX WebBrowser 页面高度和宽度

c# - 使用 Web API 在 CRM 数据库中添加查找 GUID 字段时出现错误请求错误

c# - CrmSvcUtil 仅创建 OrganizationServiceContext 派生体(应为 CrmOrganizationServiceContext)

dynamics-crm - 插件、工作流程和支持程序集的程序集路径

dynamics-crm-2011 - 如何在CRM插件中获取当前用户记录?