帮助程序代码:选项集枚举

 

发布日期: 2017年1月

适用于: Dynamics 365 (online),Dynamics 365 (on-premises),Dynamics CRM 2016,Dynamics CRM Online

SDK 下载包包括 CrmSvcUtil 代码生成工具的扩展,它可用于生成所有选项集值(包括全局选项集、选择列表、状态和状态值)的枚举。 有关详细信息,请参阅生成选项集枚举的示例扩展。 此外,它还包括帮助程序代码文件,该文件包含对所有现成值生成的枚举。 可以通过向项目中添加 SampleCode\CS\HelperCode\OptionSets.cs 或 SampleCode\VB\HelperCode\OptionSets.vb 文件来使用这些枚举。

每种枚举均可用于测试或设置属性的值。 通常,此属性是实体属性,但有些枚举可用于其他属性。

使用示例

以下示例显示如何使用其中一种枚举在 Account 实体中设置值。


// Instantiate an account object. Note the use of the option set enumerations defined
// in OptionSets.cs.
Account account = new Account { Name = "Fourth Coffee" };
account.AccountCategoryCode = new OptionSetValue((int)AccountAccountCategoryCode.PreferredCustomer);
account.CustomerTypeCode = new OptionSetValue((int)AccountCustomerTypeCode.Investor);

// Create an account record named Fourth Coffee.
// Save the record reference so we can delete it during cleanup later.
Guid accountId = service.Create(account);


' Instantiate an account object. Note the use of the option set enumerations defined in OptionSets.vb.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim account_Renamed As Account = New Account With {.Name = "Fourth Coffee"}
account_Renamed.AccountCategoryCode = New OptionSetValue(CInt(AccountAccountCategoryCode.PreferredCustomer))
account_Renamed.CustomerTypeCode = New OptionSetValue(CInt(AccountCustomerTypeCode.Investor))

' Create an account record named Fourth Coffee.
_accountId = _serviceProxy.Create(account_Renamed)

另请参阅

使用示例和帮助程序代码
帮助程序代码:ServerConnection 类
帮助程序代码:DeviceIdManager 类
帮助程序代码:SystemUserProvider 类
生成选项集枚举的示例扩展
全局选项元数据值
使用 Microsoft Dynamics 365 Web 服务运行简单程序

Microsoft Dynamics 365

© 2017 Microsoft。 保留所有权利。 版权