/// <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
} // GetParameterNames Method /// <summary> /// Set the parameter values from an initialized CmdLneArgsBasic object, /// overriding any that were initialized from the Application Settings. /// </summary> /// <param name="pcmdArgs"> /// Pass in a reference to a CmdLneArgsBasic object that was initialized /// from the string array returned by the GetParameterNames method. /// </param> /// <param name="penmParameterSource"> /// Specify the member of the ParameterSource, generic type U, /// enumeration with which to mark the object if the CmdLneArgsBasic /// object includes a value. /// /// Please <see cref="OperatingParametersCollection{T, U}"/> for more /// details. /// </param> public void SetFromCommandLineArguments ( CmdLneArgsBasic pcmdArgs , U penmParameterSource ) { lock ( s_srCriticalSection ) { IEnumerator<KeyValuePair<string , OperatingParameter<T , U>>> listOfValidArguments = _dctOperatingParameters .GetEnumerator ( ); while ( listOfValidArguments.MoveNext ( ) ) { string strName = listOfValidArguments.Current.Key; string strValue = pcmdArgs.GetArgByName ( strName ); if ( !string.IsNullOrEmpty ( strValue ) ) { OperatingParameter<T , U> opThis = listOfValidArguments.Current.Value; opThis.SetValue ( strValue , // string pstrValue penmParameterSource ); // ParameterSource penmSource } // if ( !string.IsNullOrEmpty ( strValue ) ) } // while ( listOfValidArguments.MoveNext ( ) ) } // lock ( s_srCriticalSection ) } // SetFromCommandLineArguments Method