2013-05-14 78 views
0

我正在尝试在GP Web Services中创建一个Customer,并且我遇到了Customer类的BalanceType属性,我不知道如何设置它的值。我期待它是一个值为0或1的整数,但是我收到一个“不能隐式地将类型'int'转换为[...]。BalanceType”。Dynamics GP Web Services中的BalanceType,如何使用?

这是它的定义。我相信这个问题是我对C#和.NET的总体经验以及具体的枚举类型缺乏经验。

public enum BalanceType : int { 

    [System.Runtime.Serialization.EnumMemberAttribute(Value="Open Item")] 
    OpenItem = 0, 

    [System.Runtime.Serialization.EnumMemberAttribute(Value="Balance Forward")] 
    BalanceForward = 1, 
} 

在我的代码我有一个类的属性

public int balanceType 

的方法,我有以下其中_customer是通过我的参数对象和customerObj是Web服务类对象之后。

customerObj.BalanceType = _customer.balanceType; 

您的时间和智力非常感谢。

回答

1

枚举类型提供了一种使用值定义命名常量的方便方法。在这种情况下,OpenItem = 0和BalanceForward = 1

您设置一个枚举这样的:

customerObj.BalanceType = BalanceType.OpenItem; 

我会更改属性在代码中也BalanceType像这样:

public BalanceType balanceType; 

这样可以避免在整数和枚举类型之间进行转换。您将能够轻松地设置:

customerObj.BalanceType = balanceType; 

万一你需要从一个整数转换为枚举类型,看到这个related question

相关问题