Показать сообщение отдельно
Старый 03.03.2020, 18:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
a33ik: Extend the packed list of standard class variables
Источник: http://daxonline.org/1682-extend-the...variables.html
==============

This topic shows how to extend the list of packable variables of the existing class which realize SysPackable interface or not, the class needs to have only pack and unpack methods.
For example, you want to extend the SrsPrintDestinationSettings class which have a pack and unpack method, but it did not realize SysPackable interface and add a new print setup for selecting Email Template.
The following example shows how to implement this scenario:[ExtensionOf(classStr(SrsPrintDestinationSettings))]public final class MySrsPrintDestinationSettings_Extension { private SysEmailSystemId emailTemplateId; #define.CurrentVersion(1) #localmacro.CurrentList emailTemplateId #endmacro public SrsReportEMailDataContract parmEMailContract(SrsReportEMailDataContract _emailContract) { next parmEMailContract(_emailContract); if(!emailContract.parmBody() && emailTemplateId) { SysEmailMessageTable sysEmailMessageTable = SysEmailMessageTable::find(emailTemplateId, CompanyInfo::languageId()); emailContract.parmBody(SysEmailMessage::stringExpand(sysEmailMessageTable.Mail, SysEmailMessage::createStandardPlaceholders())); } return emailContract; } [DataMemberAttribute] public SysEmailSystemId myParmEmailTemplateId(SysEmailSystemId _emailTemplateId = emailTemplateId) { emailTemplateId = _emailTemplateId; return emailTemplateId; } public container pack() { container packedClass = next pack(); return SysPackExtensions::appendExtension(packedClass, classStr(MySrsPrintDestinationSettings_Extension), this.packMyExtension()); } public boolean unpack(container _packedClass) { boolean result = next unpack(_packedClass); if (result) { container packedClassExtension = SysPackExtensions::findExtension(_packedClass, classStr(MySrsPrintDestinationSettings_Extension)); //Also unpack the extension if (!this.unpackMyExtension(packedClassExtension)) { result = false; } } return result; } private container packMyExtension() { return [#CurrentVersion, #CurrentList]; } private boolean unpackMyExtension(container _packedClass) { Integer version; if (typeOf(conPeek(_packedClass, 1)) == Types::Integer) { version = conPeek(_packedClass, 1); } else { version = RunBase::getVersion(_packedClass); } switch (version) { case #CurrentVersion: [version, #currentList] = _packedClass; break; default: return false; } return true; }}To avoid collisions with other eventual extensions, I followed these best practices:
  • Prefix members and methods. In the example, the prefix “my” is used. This practice is important because it helps prevent name clashes with other extensions and future versions of the augmented class.


If you want to extend the RunBase class, docs from MS shows how a RunBase class can be augmented end to end https://docs.microsoft.com/en-us/dyn...-runbase-class



Original post:https://daxdevblog.blogspot.com/2020...ard-class.html



Источник: http://daxonline.org/1682-extend-the...variables.html