System.Configuration.ConfigurationData.Load C# (CSharp) Метод

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

private Load ( string fileName ) : bool
fileName string
Результат bool
		public bool Load (string fileName)
		{
#if (XML_DEP)
			this.fileName = fileName;
			if (fileName == null
#if !TARGET_JVM
				|| !File.Exists (fileName)
#endif
)
				return false;
			
			XmlTextReader reader = null;

			try {
#if !TARGET_JVM
				FileStream fs = new FileStream (fileName, FileMode.Open, FileAccess.Read);
#else
				Stream fs = (Stream) vmw.common.IOUtils.getStream (fileName);

				//patch for machine.config
				if (fs == null && fileName.EndsWith ("machine.config")) {
					fs = (Stream) IOUtils.getStreamForGHConfigs (fileName);
				}

				if (fs == null) {
					return false;
				}
#endif
				reader = new XmlTextReader (fs);
				if (InitRead (reader))
					ReadConfigFile (reader);
			} catch (ConfigurationException) {
				throw;
			} catch (Exception e) {
				throw new ConfigurationException ("Error reading " + fileName, e);
			} finally {
				if (reader != null)
					reader.Close();
			}
#endif
			return true;
		}
		

Usage Example

        public void Init()
        {
            lock (this)
            {
                if (config != null)
                {
                    return;
                }

                ConfigurationData data = new ConfigurationData();
                if (data.LoadString(GetBundledMachineConfig()))
                {
                    // do nothing
                }
                else
                {
                    if (!data.Load(GetMachineConfigPath()))
                    {
                        throw new ConfigurationException("Cannot find " + GetMachineConfigPath());
                    }
                }
                string appfile = GetAppConfigPath();
                if (appfile == null)
                {
                    config = data;
                    return;
                }

                ConfigurationData appData = new ConfigurationData(data);
                if (appData.Load(appfile))
                {
                    config = appData;
                }
                else
                {
                    config = data;
                }
            }
        }
All Usage Examples Of System.Configuration.ConfigurationData::Load