Source/NFX/Environment/Configuration.cs
/// <summary>
/// Loads the supplied string content in the specified format, which may be format name like "xml" or "laconfig" with or without extension period
/// </summary>
Loads the supplied string content in the specified format, which may be format name like "xml" or "laconfig" with or without extension period
Loads the supplied string content in the specified format which may be format name like " xml " or " laconfig " with or without extension period
public static Configuration ProviderLoadFromString(string content, string format, string fallbackFormat = null)
        {
          if (format.IsNullOrWhiteSpace()) { format = fallbackFormat; fallbackFormat = null; }
          if (format != null)
          {
            if (format.StartsWith(".")) format = format.Remove(0, 1);
            if (NFX.CodeAnalysis.Laconfig.LaconfigLanguage.Instance.FileExtensions.Any(e => string.Equals(e, format, StringComparison.InvariantCultureIgnoreCase)))
              return LaconicConfiguration.CreateFromString(content);
            if (NFX.CodeAnalysis.XML.XMLLanguage.Instance.FileExtensions.Any(e => string.Equals(e, format, StringComparison.InvariantCultureIgnoreCase)))
              return XMLConfiguration.CreateFromXML(content);
            if (NFX.CodeAnalysis.JSON.JSONLanguage.Instance.FileExtensions.Any(e => string.Equals(e, format, StringComparison.InvariantCultureIgnoreCase)))
              return JSONConfiguration.CreateFromJSON(content);
            if (fallbackFormat.IsNotNullOrWhiteSpace())
              return ProviderLoadFromString(content, fallbackFormat);
          }
          throw new ConfigException(StringConsts.CONFIG_NO_PROVIDER_LOAD_FORMAT_ERROR + format);
        }
public static Configuration ProviderLoadFromString ( string content , string format , string fallbackFormat = null ) { if ( format . IsNullOrWhiteSpace ( ) ) { format = fallbackFormat ; fallbackFormat = null ; } if ( format != null ) { if ( format . StartsWith ( " " ) ) format = format . Remove ( 0 , 1 ) ; if ( NFX . CodeAnalysis . Laconfig . LaconfigLanguage . Instance . FileExtensions . Any ( e => string . Equals ( e , format , StringComparison . InvariantCultureIgnoreCase ) ) ) return LaconicConfiguration . CreateFromString ( content ) ; if ( NFX . CodeAnalysis . XML . XMLLanguage . Instance . FileExtensions . Any ( e => string . Equals ( e , format , StringComparison . InvariantCultureIgnoreCase ) ) ) return XMLConfiguration . CreateFromXML ( content ) ; if ( NFX . CodeAnalysis . JSON . JSONLanguage . Instance . FileExtensions . Any ( e => string . Equals ( e , format , StringComparison . InvariantCultureIgnoreCase ) ) ) return JSONConfiguration . CreateFromJSON ( content ) ; if ( fallbackFormat . IsNotNullOrWhiteSpace ( ) ) return ProviderLoadFromString ( content , fallbackFormat ) ; } throw new ConfigException ( StringConsts . CONFIG_NO_PROVIDER_LOAD_FORMAT_ERROR + format ) ; }
Loads the supplied string content in the specified format, which may be format name like "xml" or "laconfig" with or without extension period
Loads the supplied string content in the specified format which may be format name like " xml " or " laconfig " with or without extension period
//since C# does not support first-class types, these if statements below must handle what AllSupportedFormat returns //in future Aum conversion replace with Dictionary<format, configType> lookup
content
string
format
string
fallbackFormat
string