public BetterObjectDescriptor(object value, Type type, Type staticType, ScalarStyle scalarStyle) { Value = value; Type = type; StaticType = staticType; if (scalarStyle == ScalarStyle.Any) { var s = value as string; if (s != null) { if (Regexes.BooleanLike.IsMatch(s)) { scalarStyle = ScalarStyle.DoubleQuoted; } else if (Regexes.IntegerLike.IsMatch(s)) { scalarStyle = ScalarStyle.DoubleQuoted; } else if (Regexes.DoubleLike.IsMatch(s)) { scalarStyle = ScalarStyle.DoubleQuoted; } else if (s.StartsWith("'")) { scalarStyle = ScalarStyle.DoubleQuoted; } else if (s.StartsWith("\"")) { scalarStyle = ScalarStyle.DoubleQuoted; } } } ScalarStyle = scalarStyle; }
/// <summary> /// Initializes a new instance of the <see cref="YamlScalarNode"/> class. /// </summary> /// <param name="events">The events.</param> /// <param name="state">The state.</param> internal YamlScalarNode(EventReader events, DocumentLoadingState state) { Scalar scalar = events.Expect<Scalar>(); Load(scalar, state); Value = scalar.Value; Style = scalar.Style; }
/// <summary> /// Initializes a new instance of the <see cref="Scalar"/> class. /// </summary> /// <param name="anchor">The anchor.</param> /// <param name="tag">The tag.</param> /// <param name="value">The value.</param> /// <param name="style">The style.</param> /// <param name="isPlainImplicit">.</param> /// <param name="isQuotedImplicit">.</param> /// <param name="start">The start position of the event.</param> /// <param name="end">The end position of the event.</param> public Scalar(string anchor, string tag, string value, ScalarStyle style, bool isPlainImplicit, bool isQuotedImplicit, Mark start, Mark end) : base(anchor, tag, start, end) { this.value = value; this.style = style; this.isPlainImplicit = isPlainImplicit; this.isQuotedImplicit = isQuotedImplicit; }
public ObjectDescriptor(object value, Type type, Type staticType, ScalarStyle scalarStyle) { Value = value; if (type == null) { throw new ArgumentNullException("type"); } Type = type; if (staticType == null) { throw new ArgumentNullException("staticType"); } StaticType = staticType; ScalarStyle = scalarStyle; }
public ScalarBuilder(string text, ScalarStyle style) { this.text = text; this.style = style; plainImplicit = DefaultPlainImplicit; quotedImplicit = DefaultQuotedImplicit; }
/// <summary> /// Initializes a new instance of the <see cref="Scalar"/> class. /// </summary> /// <param name="anchor">The anchor.</param> /// <param name="tag">The tag.</param> /// <param name="value">The value.</param> /// <param name="style">The style.</param> /// <param name="isPlainImplicit">.</param> /// <param name="isQuotedImplicit">.</param> public Scalar(string anchor, string tag, string value, ScalarStyle style, bool isPlainImplicit, bool isQuotedImplicit) : this(anchor, tag, value, style, isPlainImplicit, isQuotedImplicit, Mark.Empty, Mark.Empty) { }
/// <summary> /// Initializes a new instance of the <see cref="Scalar"/> class. /// </summary> /// <param name="value">The value.</param> /// <param name="style">The style.</param> /// <param name="start">The start position of the token.</param> /// <param name="end">The end position of the token.</param> public Scalar(string value, ScalarStyle style, Mark start, Mark end) : base(start, end) { this.value = value; this.style = style; }
/// <summary> /// Initializes a new instance of the <see cref="YamlMemberAttribute" /> class. /// </summary> public YamlMemberAttribute() { ScalarStyle = ScalarStyle.Any; }
public override void Emit(ScalarEventInfo eventInfo) { ScalarStyle plain = ScalarStyle.Plain; TypeCode code = (eventInfo.Source.Value == null) ? TypeCode.Empty : eventInfo.Source.Type.GetTypeCode(); switch (code) { case TypeCode.Empty: eventInfo.Tag = "tag:yaml.org,2002:null"; eventInfo.RenderedValue = string.Empty; break; case TypeCode.Boolean: eventInfo.Tag = "tag:yaml.org,2002:bool"; eventInfo.RenderedValue = YamlFormatter.FormatBoolean(eventInfo.Source.Value); break; case TypeCode.Char: case TypeCode.String: eventInfo.Tag = "tag:yaml.org,2002:str"; eventInfo.RenderedValue = eventInfo.Source.Value.ToString(); plain = ScalarStyle.Any; break; case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: eventInfo.Tag = "tag:yaml.org,2002:int"; eventInfo.RenderedValue = YamlFormatter.FormatNumber(eventInfo.Source.Value); break; case TypeCode.Single: eventInfo.Tag = "tag:yaml.org,2002:float"; eventInfo.RenderedValue = YamlFormatter.FormatNumber((float)eventInfo.Source.Value); break; case TypeCode.Double: eventInfo.Tag = "tag:yaml.org,2002:float"; eventInfo.RenderedValue = YamlFormatter.FormatNumber((double)eventInfo.Source.Value); break; case TypeCode.Decimal: eventInfo.Tag = "tag:yaml.org,2002:float"; eventInfo.RenderedValue = YamlFormatter.FormatNumber(eventInfo.Source.Value); break; case TypeCode.DateTime: eventInfo.Tag = "tag:yaml.org,2002:timestamp"; eventInfo.RenderedValue = YamlFormatter.FormatDateTime(eventInfo.Source.Value); break; default: { if (ReferenceEquals(eventInfo.Source.Type, typeof(TimeSpan))) { eventInfo.RenderedValue = YamlFormatter.FormatTimeSpan(eventInfo.Source.Value); break; } object[] args = new object[] { code }; throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "TypeCode.{0} is not supported.", args)); } } eventInfo.IsPlainImplicit = true; eventInfo.Style ??= plain; base.Emit(eventInfo); }
public PSObjectPropertyDescriptor(PSPropertyInfo propInfo) { this.propertyInfo = propInfo; ScalarStyle = ScalarStyle.Any; }
public static MyYamlScalarNode CreateMyYamlScalarNode(string name, string tag, string value, ScalarStyle style, int indentAmount) { return(new MyYamlScalarNode(name, tag, value, style, indentAmount)); }
private Token ScanBlockScalar(bool isLiteral) { StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder2 = new StringBuilder(); StringBuilder stringBuilder3 = new StringBuilder(); int num = 0; int num2 = 0; int currentIndent = 0; bool flag = false; Mark start = cursor.Mark(); Skip(); if (analyzer.Check("+-", 0)) { num = (analyzer.Check('+', 0) ? 1 : (-1)); Skip(); if (analyzer.IsDigit(0)) { if (analyzer.Check('0', 0)) { throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, find an indentation indicator equal to 0."); } num2 = analyzer.AsDigit(0); Skip(); } } else if (analyzer.IsDigit(0)) { if (analyzer.Check('0', 0)) { throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, find an indentation indicator equal to 0."); } num2 = analyzer.AsDigit(0); Skip(); if (analyzer.Check("+-", 0)) { num = (analyzer.Check('+', 0) ? 1 : (-1)); Skip(); } } while (analyzer.IsWhite(0)) { Skip(); } ProcessComment(); if (!analyzer.IsBreakOrZero(0)) { throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, did not find expected comment or line break."); } if (analyzer.IsBreak(0)) { SkipLine(); } Mark end = cursor.Mark(); if (num2 != 0) { currentIndent = ((indent < 0) ? num2 : (indent + num2)); } currentIndent = ScanBlockScalarBreaks(currentIndent, stringBuilder3, start, ref end); while (cursor.LineOffset == currentIndent && !analyzer.IsZero(0)) { bool flag2 = analyzer.IsWhite(0); if (!isLiteral && StartsWith(stringBuilder2, '\n') && !flag && !flag2) { if (stringBuilder3.Length == 0) { stringBuilder.Append(' '); } stringBuilder2.Length = 0; } else { stringBuilder.Append(stringBuilder2.ToString()); stringBuilder2.Length = 0; } stringBuilder.Append(stringBuilder3.ToString()); stringBuilder3.Length = 0; flag = analyzer.IsWhite(0); while (!analyzer.IsBreakOrZero(0)) { stringBuilder.Append(ReadCurrentCharacter()); } char c = ReadLine(); if (c != 0) { stringBuilder2.Append(c); } currentIndent = ScanBlockScalarBreaks(currentIndent, stringBuilder3, start, ref end); } if (num != -1) { stringBuilder.Append(stringBuilder2); } if (num == 1) { stringBuilder.Append(stringBuilder3); } ScalarStyle style = (!isLiteral) ? ScalarStyle.Folded : ScalarStyle.Literal; return(new Scalar(stringBuilder.ToString(), style, start, end)); }
/// <summary> /// Initializes a new instance of the <see cref="DataStyleAttribute"/> class. /// </summary> /// <param name="style">The style.</param> public DataStyleAttribute(ScalarStyle scalarStyle) { this.ScalarStyle = scalarStyle; }
/// <summary> /// Initializes a new instance of the <see cref="Scalar"/> class. /// </summary> /// <param name="value">The value.</param> /// <param name="style">The style.</param> public Scalar(string value, ScalarStyle style) : this(value, style, Mark.Empty, Mark.Empty) { }
/// <summary> /// Initializes a new instance of the <see cref="YamlMemberAttribute" /> class. /// </summary> public YamlMemberAttribute() { ScalarStyle = ScalarStyle.Any; ApplyNamingConventions = true; }
/// <summary> /// Initializes a new instance of the <see cref="Scalar"/> class. /// </summary> /// <param name="value">The value.</param> /// <param name="style">The style.</param> /// <param name="start">The start position of the token.</param> /// <param name="end">The end position of the token.</param> public Scalar(string value, ScalarStyle style, Mark start, Mark end) : base(start, end) { this.Value = value ?? throw new ArgumentNullException(nameof(value)); this.Style = style; }
public ScalarBuilder(string text, ScalarStyle style) { this.text = text; this.style = style; plainImplicit = style == ScalarStyle.Plain; quotedImplicit = style != ScalarStyle.Plain && style != ScalarStyle.Any; }
public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter) { ScalarStyle style = ScalarStyle.Plain; TypeCode typeCode = (eventInfo.Source.Value != null) ? eventInfo.Source.Type.GetTypeCode() : TypeCode.Empty; switch (typeCode) { case TypeCode.Boolean: eventInfo.Tag = "tag:yaml.org,2002:bool"; eventInfo.RenderedValue = YamlFormatter.FormatBoolean(eventInfo.Source.Value); break; case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: eventInfo.Tag = "tag:yaml.org,2002:int"; eventInfo.RenderedValue = YamlFormatter.FormatNumber(eventInfo.Source.Value); break; case TypeCode.Single: eventInfo.Tag = "tag:yaml.org,2002:float"; eventInfo.RenderedValue = YamlFormatter.FormatNumber((float)eventInfo.Source.Value); break; case TypeCode.Double: eventInfo.Tag = "tag:yaml.org,2002:float"; eventInfo.RenderedValue = YamlFormatter.FormatNumber((double)eventInfo.Source.Value); break; case TypeCode.Decimal: eventInfo.Tag = "tag:yaml.org,2002:float"; eventInfo.RenderedValue = YamlFormatter.FormatNumber(eventInfo.Source.Value); break; case TypeCode.Char: case TypeCode.String: eventInfo.Tag = "tag:yaml.org,2002:str"; eventInfo.RenderedValue = eventInfo.Source.Value.ToString(); style = ScalarStyle.Any; break; case TypeCode.DateTime: eventInfo.Tag = "tag:yaml.org,2002:timestamp"; eventInfo.RenderedValue = YamlFormatter.FormatDateTime(eventInfo.Source.Value); break; case TypeCode.Empty: eventInfo.Tag = "tag:yaml.org,2002:null"; eventInfo.RenderedValue = string.Empty; break; default: if (eventInfo.Source.Type != typeof(TimeSpan)) { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "TypeCode.{0} is not supported.", typeCode)); } eventInfo.RenderedValue = YamlFormatter.FormatTimeSpan(eventInfo.Source.Value); break; } eventInfo.IsPlainImplicit = true; if (eventInfo.Style == ScalarStyle.Any) { eventInfo.Style = style; } base.Emit(eventInfo, emitter); }