System.Configuration.ConfigurationSchemaErrors.AddError C# (CSharp) Метод

AddError() приватный Метод

private AddError ( ConfigurationException ce, ExceptionAction action ) : void
ce ConfigurationException
action ExceptionAction
Результат void
        internal void AddError(ConfigurationException ce, ExceptionAction action) {
            switch (action) {
                case ExceptionAction.Global:
                    ErrorsHelper.AddError(ref _errorsAll, ce);
                    ErrorsHelper.AddError(ref _errorsGlobal, ce);
                    break;

                case ExceptionAction.NonSpecific:
                    ErrorsHelper.AddError(ref _errorsAll, ce);
                    break;

                case ExceptionAction.Local:
                    ErrorsHelper.AddError(ref _errorsLocal, ce);
                    break;
            }
        }

Usage Example

        // RefreshFactoryRecord
        //
        // Refresh the Factory Record for a particular section.
        //
        private void RefreshFactoryRecord(string configKey) {
            Hashtable                 factoryList   = null;
            FactoryRecord             factoryRecord = null;
            ConfigurationSchemaErrors errors;

            errors = new ConfigurationSchemaErrors();

            // Get Updated Factory List from File
            int lineNumber = 0;
            try {
                using (Impersonate()) {
                    using (Stream stream = Host.OpenStreamForRead(ConfigStreamInfo.StreamName)) {
                        if (stream != null) {
                            ConfigStreamInfo.HasStream = true;

                            using (XmlUtil xmlUtil = new XmlUtil(stream, ConfigStreamInfo.StreamName, true, errors)) {
                                try {
                                    factoryList = ScanFactories(xmlUtil);
                                    ThrowIfParseErrors(xmlUtil.SchemaErrors);
                                }
                                catch {
                                    lineNumber = xmlUtil.LineNumber;
                                    throw;
                                }
                            }
                        }
                    }
                }

                // Add implicit sections to the factory list
                if (factoryList == null) {
                    // But if factoryList isn't found in this config, we still try to
                    // add implicit sections to an empty factoryList.
                    factoryList = new Hashtable();
                }
                
                AddImplicitSections(factoryList);

                if (factoryList != null) {
                    factoryRecord = (FactoryRecord) factoryList[configKey];
                }
            }
            //
            // Guarantee that exceptions contain the name of the stream and an approximate line number if available.
            //
            // And don't allow frames up the stack to run exception filters while impersonated.
            catch (Exception e) {
                errors.AddError(
                        ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), e, ConfigStreamInfo.StreamName, lineNumber),
                        ExceptionAction.Global);

            } 
            catch {
                errors.AddError(
                        ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), null, ConfigStreamInfo.StreamName, lineNumber),
                        ExceptionAction.Global);
            }
                    
            // Set/Add/Remove Record
            // Note that the _factoryRecords hashtable is protected by the hierarchy lock.
            if (factoryRecord != null || HasFactoryRecords) {
                EnsureFactories()[configKey] = factoryRecord;
            }
            
            // Throw accumulated errors
            ThrowIfParseErrors(errors);
        }
All Usage Examples Of System.Configuration.ConfigurationSchemaErrors::AddError