#pragma warning restore SA1309 // Field names should not begin with underscore public IniFileLine(string key, string value, string section, bool comment = false) { this._Key = key; this._Value = value; this._IsCommented = comment; this._Type = IniFileLineType.Directive; this._Section = section; }
public IniFileLine(string line, string section) { if (string.IsNullOrWhiteSpace(line)) { this._Type = IniFileLineType.Blank; return; } if (line.TrimStart(" ".ToCharArray()).StartsWith(";")) { // Marcamos como comentarios para el desparseado y quitamos el caracter. this._IsCommented = true; line = this.ReplaceFirst(line, ";", string.Empty); } var parts = Regex.Split(line, "=").ToList(); if (parts.Count > 1 && ValidKey(parts.First())) { var rawkey = parts.First(); parts.RemoveAt(0); var rawvalue = string.Join("=", parts); this._Key = rawkey.Trim(); this._Value = rawvalue.Trim(); this._Type = IniFileLineType.Directive; // Creando este template conservamos los espacios originales, si los hubiera. this._Template = (string.IsNullOrEmpty(this._Key) ? "{0}" : rawkey.Replace(this._Key, "{0}")) + "=" + (string.IsNullOrEmpty(this._Value) ? "{1}" : rawvalue.Replace(this._Value, "{1}")); } else { this._Type = IniFileLineType.Comment; this._CommentBody = line; } }