コード例 #1
0
        public static IniFile Load(string content, IniLoadSettings settings = null)
        {
            settings = settings ?? IniLoadSettings.Default;
            Encoding encoding = settings.Encoding ?? Encoding.UTF8;

            byte[] contentBytes = encoding.GetBytes(content);
            var    stream       = new MemoryStream(contentBytes.Length);

            stream.Write(contentBytes, 0, contentBytes.Length);
            stream.Seek(0, SeekOrigin.Begin);
            return(new IniFile(stream));
        }
コード例 #2
0
        public IniFile(string iniFilePath, IniLoadSettings settings = null)
        {
            if (iniFilePath == null)
            {
                throw new ArgumentNullException("iniFilePath");
            }
            if (!File.Exists(iniFilePath))
            {
                throw new ArgumentException(string.Format("INI file '{0}' does not exist", iniFilePath), "iniFilePath");
            }

            settings    = settings ?? IniLoadSettings.Default;
            _comparison = settings.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            using (var reader = new StreamReader(iniFilePath, settings.Encoding ?? Encoding.UTF8, settings.DetectEncoding))
                ParseIniFile(reader);
        }
コード例 #3
0
        public IniFile(Stream stream, IniLoadSettings settings = null)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("Cannot read from specified stream", "stream");
            }

            settings    = settings ?? IniLoadSettings.Default;
            _comparison = settings.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            using (var reader = new StreamReader(stream, settings.Encoding ?? Encoding.UTF8, settings.DetectEncoding))
                ParseIniFile(reader);
        }
コード例 #4
0
 public IniFile(IniLoadSettings settings = null)
 {
     settings    = settings ?? IniLoadSettings.Default;
     _comparison = settings.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
 }