/// <summary> /// Parse exactly from <paramref name="fields"/>. /// </summary> /// <param name="fields">A <see cref="string"/> of fields that seperates with ','.</param> /// <param name="format">The <see cref="EntryHeader"/> presents its format.</param> /// <returns><see cref="Style"/> presents the <paramref name="fields"/>.</returns> /// <exception cref="ArgumentNullException">Parameters are null or empty.</exception> /// <exception cref="FormatException">Deserialize failed for some fields.</exception> /// <exception cref="KeyNotFoundException"> /// Fields of <see cref="Style"/> and fields of <paramref name="format"/> doesn't match /// </exception> public static Style ParseExact(EntryHeader format, string fields) { var re = new Style(); re.ParseExact(fields, format); return(re); }
/// <summary> /// Parse exactly from <paramref name="fields"/>. /// </summary> /// <param name="fields">A <see cref="string"/> of fields that seperates with ','.</param> /// <param name="format">The <see cref="EntryHeader"/> presents its format.</param> /// <param name="isComment">Whether the <see cref="SubEvent"/> is comment or not.</param> /// <returns><see cref="SubEvent"/> presents the <paramref name="fields"/>.</returns> /// <exception cref="ArgumentNullException">Parameters are null or empty.</exception> /// <exception cref="FormatException">Deserialize failed for some fields.</exception> /// <exception cref="KeyNotFoundException"> /// Fields of <see cref="SubEvent"/> and fields of <paramref name="format"/> doesn't match /// </exception> public static SubEvent ParseExact(EntryHeader format, bool isComment, string fields) { var re = new SubEvent(); re.ParseExact(fields, format); re.IsComment = isComment; return(re); }
/// <summary> /// Returns the ass form of this <see cref="Entry"/>, with the given <paramref name="format"/>. /// </summary> /// <param name="format">The <see cref="EntryHeader"/> presents its format.</param> /// <returns>The <see cref="string"/> presents this <see cref="Entry"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="format"/> is null.</exception> public string Serialize(EntryHeader format) { if (format == null) { throw new ArgumentNullException(nameof(format)); } var r = new EntryData(format.Select(key => this.fieldInfo[key].Serialize(this)).ToArray()); return(string.Format(FormatHelper.DefaultFormat, "{0}: {1}", EntryName, r.ToString())); }
/// <summary> /// Parse exactly from <paramref name="fields"/>, deserialize and save to this <see cref="Entry"/>. /// </summary> /// <param name="fields">A <see cref="string"/> of fields that seperates with ','.</param> /// <param name="format">The <see cref="EntryHeader"/> presents its format.</param> /// <exception cref="ArgumentNullException">Parameters are null or empty.</exception> /// <exception cref="FormatException">Deserialize failed for some fields.</exception> /// <exception cref="KeyNotFoundException"> /// Fields of <see cref="Entry"/> and fields of <paramref name="format"/> doesn't match /// </exception> protected void ParseExact(string fields, EntryHeader format) { if (format == null) { throw new ArgumentNullException(nameof(format)); } if (string.IsNullOrEmpty(fields)) { throw new ArgumentNullException(nameof(fields)); } var data = new EntryData(fields, format.Count); for (var i = 0; i < format.Count; i++) { this.fieldInfo[format[i]].DeserializeExact(this, data[i]); } }
/// <summary> /// Parse from <paramref name="fields"/>, deserialize and save to this <see cref="Entry"/>. /// </summary> /// <param name="fields">A <see cref="string"/> of fields that seperates with ','.</param> /// <param name="format">The <see cref="EntryHeader"/> presents its format.</param> /// <exception cref="ArgumentNullException">Parameters are null or empty.</exception> /// <exception cref="FormatException">Deserialize failed for some fields.</exception> protected void Parse(string fields, EntryHeader format) { if (format == null) { throw new ArgumentNullException(nameof(format)); } if (string.IsNullOrEmpty(fields)) { throw new ArgumentNullException(nameof(fields)); } var data = new EntryData(fields, format.Count); for (var i = 0; i < format.Count; i++) { if (!this.fieldInfo.TryGetValue(format[i], out var target)) { continue; } target.Deserialize(this, data[i]); } }
private void initStyle(string styleLine) { if (FormatHelper.TryPraseLine(out var key, out var value, styleLine)) { switch (key.ToLower()) { case "format": this.styleFormat = new EntryHeader(value); return; case "style": if (this.styleFormat == null) { this.styleFormat = DefaultStyleFormat; } Style s; if (this.isExact) { s = Style.ParseExact(this.styleFormat, value); if (this.subtitle.StyleSet.ContainsName(s.Name)) { throw new ArgumentException($"Style with the name \"{s.Name}\" is already in the StyleSet."); } } else { s = Style.Parse(this.styleFormat, value); } this.subtitle.StyleSet.Add(s); return; default: return; } } }