我正在编写一个插件,我在其中检查字段的特定值,选项集是否等于特定值,如果是,那么我会执行某些操作。
现在,在插件 C# 代码中,我如何检查选项集字段是否不为空 - 即,是否设置为默认值?
我所做的(显然,这是错误的)因为它从未超过 Null 检查语句。而且,如果我没有支票,那么我会收到此错误消息
错误:
Unexpected exception from plug-in (Execute): CRM.AppStateHandler.Plugins.PostApplicationCreate: System.NullReferenceException: Object reference not set to an instance of an object.
代码:
application applicationEntity = entity.ToEntity<new_application>();
if (new_applicationEntity.new_Applicationstatus != null)
{
var applicationStatus = applicationEntity.new_Applicationstatus.Value;
if (applicationStatus == CRMConstants.EntityApplication.Attributes.ApplicationStatusOptions.Applying)
{
//my logic
}
}
文件 constants.cs 有以下内容
class CRMConstants
{
public struct EntityApplication
{
public struct Attributes
{
public struct ApplicationStatusOptions
{
// More before this
public const int Applying = 100000006;
// More to come
}
}
}