30.07.2008, 00:05
|
#1
|
Участник
|
axStart: Using base enums in your .net connector
Источник: http://axstart.spaces.live.com/Blog/...C0A0!363.entry
==============
When using Dynamics AX base enums in C#, the created code gets a little bit ugly. We have to use the base enum values (integer) instead of the element name. This approach belongs, to my opinion to the ‘BAD’ practices.
A clean solution is creating the base enums in C#. A baseenum ABC with elements None,A,B,C would look like this in C#, I have added underscore in the C# code because the baseEnum can contain reserved words.
Public enum _ABC {_None = 0,_A, _B, _C}
From this point we can fake the base enum behavior in C#. Example set Blocked field on the Customer table
Public enum_CustVendorBlocked {_No = 0 , _Invoice = 1 , _All = 2}
Public void test()
{
AxaptaRecord custTable;
_CustVendorBlocked blocked;
//BAD practice
custTable.setField("Blocked",1);
//BAD practice
//BEST practice
custTable.setField("Blocked",(System.Int32)_CustVendorBlocked._Invoice);
blocked = (_CustVendorBlocked) AxCustTable.getField(("Blocked");
//BEST practice
}
It is also possible to place all baseEnums in an aditional namespace. You could generate this namespace from AX
namespace BaseEnums
{
public enum _NoYes { _no =0 , _yes}
public enum _ABC {_None = 0 , _A = 1 , _B = 2 , _C = 3}
public enum _ABCModel {_Revenue = 0 , _ContributionMargin = 1 , _Value = 2 , _Link = 3}
public enum _AcceptReject {_Reject = 0 , _Accept = 1}
public enum _AccountChoice {_Account = 0 , _Selection = 1}
public enum _AccountOffsetaccount {_Account = 0 , _OffsetAccount = 1}
public enum _AccountOrder {_None = 0 , _Account = 1 , _Order = 2 , _Auto = 3}
ETC ….
ETC …
Источник: http://axstart.spaces.live.com/Blog/...C0A0!363.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
|
|