CRM 2011生成的代码使用ICodeWriterFilterService构建失败 [英] CRM 2011 generated code using ICodeWriterFilterService fails to build

查看:224
本文介绍了CRM 2011生成的代码使用ICodeWriterFilterService构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用示例代码在 HTTP://erikpool.blogspot .COM / 2011/03 /过滤生成实体-with.html 我已经改变了这一点,以便GenerateEntity和GenerateOptionSet有代码:

Using the sample code at http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html I have altered this so that GenerateEntity and GenerateOptionSet to have the code:

返回optionSetMetadata.Name.ToLowerInvariant()StartsWith(myprefix);

这生成类型,包括一些枚举为optionsets。在实体optionset的实际执行不但是用这个,但我得到了以下内容:

This generates the types including some enumerations for the optionsets. The actual implementation of the optionset in the entity doesn't use this however, but I get the following:

    [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");
        }
    }



显然铸造OptionSetValue为int的二传手呢未编译,我认为它应当产生具有类型相匹配的生成枚举,但不是属性。什么我需要做的纠正呢?

Obviously casting the OptionSetValue to an int in the setter does not compile, I assume that it should be generating the property with a type that matches the generated enum, but isn't. What do I need to do to correct this?

推荐答案

它看起来像有是已被固定在crmsrvcutil一个bug 。我对OptionSet性质代码现在看起来是这样的:

It looks like there was a bug in the crmsrvcutil that has since been fixed. My code for OptionSet properties now looks like this:

[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 ...

And I get no error setting the OptionSetValue...

这篇关于CRM 2011生成的代码使用ICodeWriterFilterService构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆