} // void ListObjectProperties /// <summary> /// Enumerate the properties of an object, showing for each its type and /// value, as a formatted listing. /// </summary> /// <param name="pstrNameOfObject"> /// Name of object as it appears in the calling routine /// </param> /// <param name="pObjThisOne"> /// Reference to the object from which to enumerate properties /// </param> /// <param name="pintLeftPadding"> /// Optional left padding for the report /// </param> /// <param name="pstrObjectLabelSuffix"> /// Optional supplementary label information for the object /// </param> /// <param name="penmBindingFlags"> /// Binding flags mask, which determines which properties are enumerated /// </param> public static void ListObjectPropertyTypesAndValues ( string pstrNameOfObject, object pObjThisOne, int pintLeftPadding = ListInfo.EMPTY_STRING_LENGTH, string pstrObjectLabelSuffix = null, BindingFlags penmBindingFlags = DEFAULT_BINDING_FLAGS ) { string strIndentation = pintLeftPadding > ListInfo.EMPTY_STRING_LENGTH ? StringTricks.StrFill ( SpecialCharacters.SPACE_CHAR , pintLeftPadding ) : SpecialStrings.EMPTY_STRING; PropertyInfo [ ] apropertyInfos = pObjThisOne.GetType ( ).GetProperties ( penmBindingFlags ); int intMaxDigits = apropertyInfos.Length.ToString ( ).Length; // Compute the width of the largest possible ordinal. Console.WriteLine ( Properties.Resources.MSG_PROPERTY_LIST_HEADER , // Format Control String strIndentation , // Format Item 0: {0}Object pstrNameOfObject , // Format Item 1: Object {1} pstrObjectLabelSuffix == null // Format Item 2: {2} exposes the ? SpecialStrings.EMPTY_STRING // when pstrObjectLabelSuffix == null : $" ({pstrObjectLabelSuffix})" , // when pstrObjectLabelSuffix != null apropertyInfos.Length , // Format Item 3: exposes the following {2} Environment.NewLine ); // Format Item 4: public properties:{4} for ( int intPropertyIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ; intPropertyIndex < apropertyInfos.Length ; intPropertyIndex++ ) { try { Console.WriteLine ( Properties.Resources.MSG_PROP_TYPE_AND_VALUE_DETAIL , // Format Control String strIndentation , // Format Item 0: {0}Property NumericFormats.FormatIntegerLeftPadded ( // Format Item 1: Property {1}: ArrayInfo.OrdinalFromIndex ( // Get the ordinal equivalent to array subscript. intPropertyIndex ) , // Array subscript for which to get the corresponding ordinal. intMaxDigits ) , // Right align to this width. apropertyInfos [ intPropertyIndex ].Name , // Format Item 2: : {2} apropertyInfos[intPropertyIndex].PropertyType.FullName ,// Format Item 3: ({3}) = StringTricks.TruncateValueToOneLine ( // Format Item 4: = {4} apropertyInfos [ intPropertyIndex ].GetValue ( // Get value from the apropertyInfos in array slot intPropertyIndex. pObjThisOne , // Object from which to get property value. null ) ) ); // The null CultureInfo causes the method to infer the culture of the calling thread. } catch ( TargetInvocationException ex ) { Console.WriteLine ( Properties.Resources.ERRMSG_PROPERTY_LIST , // Format Control String strIndentation , // Format Item 0: {0}Property ArrayInfo.OrdinalFromIndex ( intPropertyIndex ) , // Format Item 1: Property {1}: apropertyInfos [ intPropertyIndex ].Name , // Format Item 2: : {2} = ex.Message ); // Format Item 3: = {3} } } // for ( int intPropertyIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ; intPropertyIndex < apropertyInfos.Length ; intPropertyIndex++ ) Console.WriteLine ( Properties.Resources.MSG_PROPERTY_LIST_FOOTER , // Format Control String strIndentation , // Format Item 0 Environment.NewLine ); // Format Item 1 } // void ListObjectPropertyTypesAndValues
} // TestFormatItemBuilders internal static void TestFormatItemCounters ( ) { const string ANNOUNCE_BEGIN = @"{1} Format strings to test = {0}{1}"; const string ANNOUNCE_DONE = @"{1} {0} format strings have been tested."; const string PROGRESS_MSG = @" String {0,2:N0}: {1}{3} Highest Index: {2}{3}"; const string FORMAT_STRING_ERRORS_PROLOGUE = @"{0} error found in format string: {1}{2}"; int intNStrings = s_astrFormatStringSamples.Length; int [ ] aintHightesItemIndex = new int [ intNStrings ]; ASCII_Table_Gen ( ); Console.WriteLine ( ANNOUNCE_BEGIN , intNStrings , Environment.NewLine ); try { for ( int intCurrStr = ARRAY_FIRST_ELEMENT ; intCurrStr < intNStrings ; intCurrStr++ ) { int intStringNumber = intCurrStr + ARRAY_LIST_ORDINAL_TO_SUBSCRIPT; FormatStringParser fsp = new FormatStringParser ( s_astrFormatStringSamples [ intCurrStr ] ); aintHightesItemIndex [ intCurrStr ] = fsp.HighestFormatItemIndex; Console.WriteLine ( PROGRESS_MSG , new object [ ] { intStringNumber , // Format Item 0 s_astrFormatStringSamples [ intCurrStr ] , // Format Item 1 aintHightesItemIndex [ intCurrStr ] , // Format Item 2 Environment.NewLine // Format Item 3 } ); if ( fsp.FormatStringErrorCount > FormatStringParser.NO_ERRORS ) { Console.WriteLine ( FORMAT_STRING_ERRORS_PROLOGUE , // Message template string fsp.FormatStringErrorCount , // Format Item 0 = Error count StringTricks.AdjustNumberOfNoun ( // Format Item 1 = Aligned error count ( uint ) fsp.FormatStringErrorCount , // puintNumber Properties.Resources.ERRMSG_LITERAL_ERROR , // pstrNounSingular null , // pstrPluralForm fsp.FormatString ) , // pstrPhrase Environment.NewLine ); // Format Item 2 = Embedded Newline ListAllErrors ( fsp.FormatStringErrors ); Console.WriteLine ( ); } // if ( fsp.FormatStringErrorCount > FormatStringParser.NO_ERRORS ) } // for ( int intCurrStr = ARRAY_FIRST_ELEMENT ; intCurrStr < intNStrings ; intCurrStr++ ) } catch ( Exception exAll ) { // Preserve this expected exception report in the standard output, in addition to sending it to Standard Error. Program.s_smTheApp.AppExceptionLogger.ReportException ( exAll ); } // ---------------------------------------------------------------- // After adding another format item into which to have WriteLine // stuff the newline, I searched down here, only to find that the // argument list already had one. The lesson from this is that you // can have extra format items in the list, but the list must have // at least enough format items to account for the highest index in // the format control string. // ---------------------------------------------------------------- Console.WriteLine ( ANNOUNCE_DONE , intNStrings , Environment.NewLine ); } // TestFormatItemCounters
static TimedWaitTestCase ( ) { const string LBL_PUINTWAITSECONDS = @"puintWaitSeconds"; const string LBL_PSTRCOUNTDOWNWAITINGFOR = @"pstrCountdownWaitingFor"; const string LBL_PCLRTEXTCOLOR = @"pclrTextColor"; const string LBL_PCLRTEXTBACKGROUNDCOLOR = @"pclrTextBackgroundColor"; const string LBL_PENMINTERRUPTCRITERION = @"penmInterruptCriterion"; s_astrTimedWaitTestCaseInfo = Properties.Resources.TIMED_WAIT_TEST_CASE_INFO.Split ( new char [ ] { SpecialCharacters.COMMA } ); int intPosition = ArrayInfo.ARRAY_INVALID_INDEX; foreach ( string strThisLabel in s_astrTimedWaitTestCaseInfo ) { intPosition++; switch ( strThisLabel ) { case LBL_PUINTWAITSECONDS: s_intPos_puintWaitSeconds = intPosition; break; case LBL_PSTRCOUNTDOWNWAITINGFOR: s_intPos_pstrCountdownWaitingFor = intPosition; break; case LBL_PCLRTEXTCOLOR: s_intPos_pclrTextColor = intPosition; break; case LBL_PCLRTEXTBACKGROUNDCOLOR: s_intPos_pclrTextBackgroundColor = intPosition; break; case LBL_PENMINTERRUPTCRITERION: s_intPos_penmInterruptCriterion = intPosition; break; default: string strMsg = string.Format ( Properties.Resources.TIMED_WAIT_TEST_CTOR_ERROR_1 , // Message template new string [ ] { Properties.Resources.TIMED_WAIT_TEST_CASE_INFO , // Token 0 strThisLabel , // Token 1 intPosition.ToString ( ) , // Token 2 Environment.NewLine // Token 3 } ); Console.Error.WriteLine ( strMsg ); // Rather than throwing an exception, emit a message into the Standard Error stream. break; } // switch ( strThisLabel ) } // foreach ( string strThisLabel in s_astrTimedWaitTestCaseInfo ) if ( s_intPos_puintWaitSeconds == ArrayInfo.ARRAY_INVALID_INDEX ) { string strMsg = string.Format ( Properties.Resources.TIMED_WAIT_TEST_CTOR_ERROR_2 , // Message template LBL_PUINTWAITSECONDS , // Token 0 StringTricks.QuoteString ( Properties.Resources.TIMED_WAIT_TEST_CASE_INFO ) ); // Token 1 Console.Error.WriteLine ( strMsg ); // Rather than throwing an exception, emit a message into the Standard Error stream. } // if ( s_intPos_puintWaitSeconds == ArrayInfo.ARRAY_INVALID_INDEX ) if ( s_intPos_pstrCountdownWaitingFor == ArrayInfo.ARRAY_INVALID_INDEX ) { string strMsg = string.Format ( Properties.Resources.TIMED_WAIT_TEST_CTOR_ERROR_2 , // Message template LBL_PSTRCOUNTDOWNWAITINGFOR , // Token 0 StringTricks.QuoteString ( Properties.Resources.TIMED_WAIT_TEST_CASE_INFO ) ); // Token 1 Console.Error.WriteLine ( strMsg ); // Rather than throwing an exception, emit a message into the Standard Error stream. } // if ( s_intPos_pstrCountdownWaitingFor == ArrayInfo.ARRAY_INVALID_INDEX ) if ( s_intPos_pclrTextColor == ArrayInfo.ARRAY_INVALID_INDEX ) { string strMsg = string.Format ( Properties.Resources.TIMED_WAIT_TEST_CTOR_ERROR_2 , // Message template LBL_PCLRTEXTCOLOR , // Token 0 StringTricks.QuoteString ( Properties.Resources.TIMED_WAIT_TEST_CASE_INFO ) ); // Token 1 Console.Error.WriteLine ( strMsg ); // Rather than throwing an exception, emit a message into the Standard Error stream. } // if ( s_intPos_pclrTextColor == ArrayInfo.ARRAY_INVALID_INDEX ) if ( s_intPos_pclrTextBackgroundColor == ArrayInfo.ARRAY_INVALID_INDEX ) { string strMsg = string.Format ( Properties.Resources.TIMED_WAIT_TEST_CTOR_ERROR_2 , // Message template LBL_PCLRTEXTBACKGROUNDCOLOR , // Token 0 StringTricks.QuoteString ( Properties.Resources.TIMED_WAIT_TEST_CASE_INFO ) ); // Token 1 Console.Error.WriteLine ( strMsg ); // Rather than throwing an exception, emit a message into the Standard Error stream. } // if ( s_intPos_pclrTextBackgroundColor == ArrayInfo.ARRAY_INVALID_INDEX ) if ( s_intPos_penmInterruptCriterion == ArrayInfo.ARRAY_INVALID_INDEX ) { string strMsg = string.Format ( Properties.Resources.TIMED_WAIT_TEST_CTOR_ERROR_2 , // Message template LBL_PENMINTERRUPTCRITERION , // Token 0 StringTricks.QuoteString ( Properties.Resources.TIMED_WAIT_TEST_CASE_INFO ) ); // Token 1 Console.Error.WriteLine ( strMsg ); // Rather than throwing an exception, emit a message into the Standard Error stream. } // if ( s_intPos_penmInterruptCriterion == ArrayInfo.ARRAY_INVALID_INDEX ) s_achrFieldDelimiter = Properties.Resources.TIMED_WAIT_TEST_DELIMITER.ToCharArray ( ListInfo.SUBSTR_BEGINNING , MagicNumbers.PLUS_ONE ); } // static TimedWaitTestCase