Azavea.Open.Common.Config.GetParametersAsList C# (CSharp) Method

GetParametersAsList() public method

Gets you a list of all the parameters for the component as key-value-pairs. This preserves the order of parameters from the config file.
public GetParametersAsList ( string component ) : string>>.IList
component string The component or section of the config file, used to /// locate the parameter.
return string>>.IList
        public virtual IList<KeyValuePair<string, string>> GetParametersAsList(string component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component", "Component cannot be null.");
            }
            try
            {
                // Convert to upper for case insensitivity.
                return new List<KeyValuePair<string, string>>(_orderedParamsByComponent[component]);
            }
            catch (Exception ex)
            {
                ReThrowException("Error while getting params as IList.",
                    new object[] { ConfigFile, component }, ex);
                // that throws, but the compiler wants a return statement.
                return null;
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// This handles running through the configuration and getting the request
        /// and response processors.
        /// </summary>
        /// <param name="config">The config file we are using.</param>
        /// <param name="sectionName">The config section we are using to look for RequestProcessors and ResponseProcessors.</param>
        private void GetProcessors(Config config, string sectionName)
        {
            if (config.ComponentExists(sectionName))
            {
                IList<KeyValuePair<string, string>> kvps = config.GetParametersAsList(sectionName);
                foreach (KeyValuePair<string, string> kvp in kvps)
                {
                    string typeName = kvp.Value;
                    Type processorType = Type.GetType(typeName);
                    if (processorType != null && typeof(IProcessor).IsAssignableFrom(processorType))
                    {
                        ConstructorInfo ci = processorType.GetConstructor(new [] {typeof (Config), typeof (string)});
                        IProcessor p;
                        if (ci != null)
                        {
                            p = (IProcessor) ci.Invoke(new object[] {config, kvp.Key});
                        }
                        else
                        {
                            ci = processorType.GetConstructor(new Type[] {});
                            if (ci == null)
                            {
                                throw new ConfigurationErrorsException("Processor '" + typeName +
                                                                       "' was specified, but we were unable to get constructor info.");
                            }
                            p = (IProcessor) ci.Invoke(new object[] {});
                        }

                        // At this point we have a processor object.  Add it to the dictionary.
                        if (p as IRequestProcessor != null)
                        {
                            _processors[typeof (IRequestProcessor)].Add(p);
                        }
                        if (p as IResponseProcessor != null)
                        {
                            _processors[typeof (IResponseProcessor)].Add(p);
                        }
                    }
                }
            }
        }
All Usage Examples Of Azavea.Open.Common.Config::GetParametersAsList