Variable Define( VariableDefinition definition, params Object[] replacements ) { clear(); Delim= definition.Delim; FormatHints= definition.FormatHints; FormatAttrAlignment= definition.FormatAttrAlignment; // set Category, Name, Comment if( definition.Category != null ) Category._( definition.Category ); else Category._( definition.CategoryFallback ); Name ._( definition.Name ); Comments._( definition.Comments ); if ( definition.DefaultValue != null ) DefaultValue._()._( definition.DefaultValue ); else DefaultValue.SetNull(); // replace strings if ( replacements != null && replacements.Length > 0 ) { AString search= Fullname; // just an alias name AString repl= new AString(); values.Add(repl); // reuse this string later for( int i= 0; i < replacements.Length; i++ ) { search._()._("%")._(i + 1); repl ._()._( replacements[i] ); Category .SearchAndReplace( search, repl ); Name .SearchAndReplace( search, repl ); Comments .SearchAndReplace( search, repl ); DefaultValue.SearchAndReplace( search, repl ); } search._(); } // set full name if( Category.IsNotEmpty() ) Fullname._( Category )._( '_' ); Fullname._( Name ); ALIB.ASSERT_WARNING( Name.IsNotEmpty(), "Empty variable name given" ); return this; }
/** **************************************************************************************** * Constructs a variable from a definition. * Strings named \c "%1", \c "%2" ... \c "%N" found in the fields #Category, #Name, * #Comments and #DefaultValue are replaced with given replacement strings found * in vector \p replacements. * * @param definition The definition data of the variable. * @param replacements List of objects that will be converted to strings using * \ref cs::aworx::lib::strings::AString::_(Object) "AString._(Object)". ******************************************************************************************/ public Variable( VariableDefinition definition, params Object[] replacements ) { Define( definition, replacements ); }