28.05.2014, 10:11 | #1 |
Участник
|
littleax: Part2. Dynamics ax 2012. Split construct method by models.
Источник: http://littleax.blogspot.com/2014/05...method_26.html
============== Split construct method by models. Part2. Last time we try to resolve problem with separate construct method by model in one layer using new future in ax delegate and event handler. At this article try to resolve this problem using another way. This way was got from Unit testing (source Classes\SysTestCase\testMethods + Classes\SysTest\invoke - try to find methods from object for specific mask), and now in AX 2012 we can find very similar way using name conversational in financial dimension (\Classes\DimensionEnabledType\getSystemDefinedDimensionsServer - try to find Views by name consist of specific mask). Lets try use this way. From previous topic we have next conditions
in TestBaseClass (model A01) we create new static method constructFromCode() X++: public static TestBaseClass constructFromCode(SalesTable _salesTable) { #define.codeConstructor('codeConstructor') TestBaseClass ret; SysDictClass sysDictClass = new SysDictClass(classNum(TestBaseClass)); DictMethod method = null; Set methods; SetEnumerator se; Set orderedSet = new Set(Types::String); ExecutePermission executePermission; ; // source Classes\SysTestCase\testMethods methods = sysDictClass.methods(false, true, false); se = methods.getEnumerator(); while (se.moveNext()) { method = se.current(); if (method && method.accessSpecifier() == AccessSpecifier::public && method.returnType() != Types::void && method.parameterCnt() == 1) { if (strStartsWith(method.name(), #codeConstructor)) { orderedSet.add(method.name()); } } // if methods } // while // part 2 - split init call // source \Classes\SysTest\invoke executePermission = new ExecutePermission(); executePermission.assert(); se = orderedSet.getEnumerator(); while (se.moveNext()) { // part 2.1 call methods ret = sysDictClass.callStatic(se.current(), _salesTable); if (ret) break; } CodeAccessPermission::revertAssert(); // init default value if (!ret) { ret = new TestBaseClass(); } ret.parmSalesTable(_salesTable); return ret; } codeConstructorClass01_M01 in A01 model X++: public static TestBaseClass codeConstructorClass01_M01(SalesTable _salesTable) { TestBaseClass01_Model01 testBaseClass01_Model01 = TestBaseClass01_Model01::construct(); if (testBaseClass01_Model01.findDetermination(_salesTable)) return testBaseClass01_Model01; return null; } X++: public static TestBaseClass codeConstructorClass02_M03(SalesTable _salesTable) { TestBaseClass02_Model02 testBaseClass02_Model02 = TestBaseClass02_Model02::construct(); if (testBaseClass02_Model02.findDetermination(_salesTable)) return testBaseClass02_Model02; return null; } X++: [COLOR=blue]static void TestBaseClass2(Args _args) { SalesTable salesTable; // cursor TestBaseClass baseClass; setPrefix("SalesInfo2"); while select salesTable { baseClass = TestBaseClass::constructFromCode(salesTable); baseClass.showInfo(); } info("done"); } Results Summary: we can use various way to create construct method without depends from models and layers. Источник: http://littleax.blogspot.com/2014/05...method_26.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. Последний раз редактировалось mazzy; 28.05.2014 в 13:21. |
|
|
|