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

LoadString() публичный Метод

public LoadString ( string data ) : bool
data string
Результат bool
		public bool LoadString (string data)
		{
			if (data == null)
				return false;
#if (XML_DEP)
			XmlTextReader reader = null;

			try {
				TextReader tr = new StringReader (data);
				reader = new XmlTextReader (tr);
				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::LoadString