/// <summary> /// The static constructor calls this method to initialize the singleton /// returned by the base constructor. /// </summary> /// <param name="psettingsPropertyValueCollection"> /// Pass a reference to a System.Configuration.SettingsPropertyCollection /// collection to display. /// </param> /// <param name="pstrDisplayNameTemplate"> /// This paramter specifies a template from which to construct the name /// of a managed string resource in the calling assembly to use as the /// display name. If no such string exists, the InternalName property is /// the display name. Likewise, if this string is a null reference or /// the empty string, the InternalName property is the display name. /// </param> /// <param name="penmDefaultParameterSource"> /// This parameter specifies the value source enumeration member to use /// as the parameter source for any OperatingParameter for which the /// ApplicationSettings has a value. /// </param> private void InitiaalizeInstance ( System.Configuration.SettingsPropertyCollection psettingsPropertyValueCollection , string pstrDisplayNameTemplate , U penmDefaultParameterSource ) { // ---------------------------------------------------------------- // Generic dictionary _dctOperatingParameters, which holds the // collection of OperatingParameter objects, indexed by name, is // initialized and sized per the count of argument names, while the // local dctParameterTypeInfo dictionary is initialized from the // string array constructed from PARAMETER_TYPE_INFO_RESOURCE_NAME, // an embedded text file resource. Iterating the argument names in // pastrArgNames, the foreach loop extracts its internally-defined // properties from dctParameterTypeInfo, the local dictionary, so // that an OperatingParameter object, with its Value property left // uninitialized, can be stored in the _dctOperatingParameters // dictionary, so that it can be quickly found and updated with the // value read from a command line argument, which happens in the // calling routine after this method returns the fully loaded // _dctOperatingParameters dictionary. // // Since everything that went into dctParameterTypeInfo is encoded // into an OperatingParameter, local object dctParameterTypeInfo is // redundant, and is allowed to vanish when the method returns. // ---------------------------------------------------------------- Dictionary<string , ParameterTypeInfo<T>> dctParameterTypeInfo = GetParameterTypeInfo ( EmbeddedTextFile.Readers.LoadTextFileFromEntryAssembly ( PARAMETER_TYPE_INFO_RESOURCE_NAME ) ); _dctOperatingParameters = new Dictionary<string , OperatingParameter<T , U>> ( dctParameterTypeInfo.Count ); foreach ( string strName in dctParameterTypeInfo.Keys ) { ParameterTypeInfo<T> ptiForThis = null; if ( dctParameterTypeInfo.TryGetValue ( strName , out ptiForThis ) ) { // Create the uninitialized parameter object, and add it to the collection. OperatingParameter<T , U> opThis = new OperatingParameter<T , U> ( psettingsPropertyValueCollection , strName , // string pstrInternalName pstrDisplayNameTemplate , // string pstrDisplayName - The constructor will sort it out. ptiForThis.ParameterType , // T penmParameterType penmDefaultParameterSource ); // U penmDefaultParameterSource _dctOperatingParameters.Add ( // Add it to the collection. strName , // Key opThis ); // Value } // TRUE (anticipated outcome) block, if ( dctParameterTypeInfo.TryGetValue ( strName , out ptiForThis ) ) else { // Prepare and log a detailed exception report. string strMessage = string.Format ( // Assemble a detailed diagnostic message. Properties.Resources.ERRMSG_INTERNAL_PROCESSING_ERROR_005 , // Format control string strName , // Format Item 0: Type information for the {0} parameter PARAMETER_TYPE_INFO_RESOURCE_NAME , // Format Item 1: cannot be found in the embedded {1} resource Environment.NewLine ); // Format Item 2: Platform-dependent newline sequence throw new InvalidOperationException ( strMessage ); // Toss cookies and die. } // FALSE (unanticipated outcome) block, if ( dctParameterTypeInfo.TryGetValue ( strName , out ptiForThis ) ) } // foreach ( string strName in dctParameterTypeInfo.Keys ) } // InitiaalizeInstance Method
} // private void InitializeOnFirstUse /// <summary> /// This method creates a generic dictionary of ParameterTypeInfo /// objects, keyed by parameter name from an array of strings, each of which /// is the internal name of a parameter. /// </summary> /// <param name="pastrParameterTypeInfoArray"> /// This array of strings is a list of parameter names and property /// values, such as generic ParameterType enumeration values, that is /// read from a TAB delimited text file that is stored in an embeddede /// assembly resource. /// /// The first string is expected to be a label row that maps the fields /// in the remaining strings to their values. /// </param> /// <returns> /// If it succeeds, the return value is a populated dictionary of /// ParameterTypeInfo objects keyed by their internal parameter names. /// Invalid data or a corrupted parameter resource file causes the /// ParameterTypeInfo constructor to throw an InvalidOperationException. /// </returns> /// <exception cref="InvalidOperationException"> /// A detailed InvalidOperationException exception report arises if the /// array of parameters is invalid. /// /// Correct code should never throw this exception. /// </exception> private Dictionary<string , ParameterTypeInfo<T>> GetParameterTypeInfo ( string [ ] pastrParameterTypeInfoArray ) { Dictionary<string , ParameterTypeInfo<T>> rdctParameterTypeInfo = new Dictionary<string , ParameterTypeInfo<T>> ( ArrayInfo.IndexFromOrdinal ( pastrParameterTypeInfoArray.Length ) ); for ( int intPosition = ArrayInfo.ARRAY_SECOND_ELEMENT ; intPosition < pastrParameterTypeInfoArray.Length ; intPosition++ ) { ParameterTypeInfo<T> pti = new ParameterTypeInfo<T> ( pastrParameterTypeInfoArray [ intPosition ] , // string pstrParameterInfoDetail pastrParameterTypeInfoArray [ ArrayInfo.ARRAY_FIRST_ELEMENT ] ); // string pastrParameterInfoColumnNames rdctParameterTypeInfo.Add ( pti.ParameterName , // Key pti ); // Value } // for ( int intPosition = ArrayInfo.ARRAY_SECOND_ELEMENT ; intPosition < pastrParameterTypeInfoArray.Length ; intPosition++ ) return rdctParameterTypeInfo; } // GetParameterTypeInfo