2013-05-14 24 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