/// <inheritdoc /> public object Read(CSStreamReader stream, string key, string genericTypeInfo, string dimensionInfo) { StringBuilder sb = new StringBuilder(128); while (stream.ReadChar(out char c)) { switch (c) { case '[': { stream.ReadEndTag(key); genericTypeInfo.GetInnerType(out string bti, out string gti); if (!string.IsNullOrEmpty(gti)) { throw new CSReaderException( $"ERROR: AN ENUM CAN't BE A GENERIC TYPE -> {genericTypeInfo}"); } Type enumType = bti.CreateType(); if (enumType.IsEnum) { return(Enum.Parse(enumType, sb.ToString())); } throw new CSReaderException($"ERROR: BASE TYPE ISN'T AN ENUM TYPE -> {bti}"); } case ']': throw new CSReaderException($"ERROR: INVALID CONTENT -> {sb}"); } sb.Append(c); } throw new CSReaderException($"ERROR: INVALID FILE CONTENT! - > {sb}"); }
/// <inheritdoc /> public object Read(CSStreamReader stream, string key, string genericTypeInfo, string dimensionInfo) { StringBuilder sb = new StringBuilder(128); while (stream.ReadChar(out char c)) { switch (c) { //ESCAPE case '\\': { if (!stream.ReadChar(out c)) { throw new CSReaderException($"ERROR: UNEXPECTED END OF FILE! - > {sb}"); } } break; case '[': { stream.ReadEndTag(key); return(sb.ToString()); } case ']': throw new CSReaderException($"ERROR: INVALID CONTENT -> {sb}"); } sb.Append(c); } throw new CSReaderException($"ERROR: INVALID FILE CONTENT! - > {sb}"); }
/// <inheritdoc /> public object Read(CSStreamReader stream, string key, string genericTypeInfo, string dimensionInfo) { StringBuilder sb = new StringBuilder(32); while (stream.ReadChar(out char c)) { switch (c) { case '[': { stream.ReadEndTag(key); string content = sb.ToString(); try { return(System.Convert.ChangeType(content, BaseType)); } catch { throw new InvalidCastException( $"content '{content}' can't be converted to '{BaseType.FullName}'!"); } } case ']': case '\r': case '\n': case '\t': throw new CSReaderException($"ERROR: INVALID CONTENT -> {sb}"); } sb.Append(c); } throw new CSReaderException($"ERROR: INVALID FILE CONTENT! - > {sb}"); }