gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:02:01 25 4
gpt4 key购买 nike

使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com