Beispiel #1
0
        public static void WriteInto(StringBuilder builder, SdlValue value)
        {
            switch (value.Type)
            {
            case SdlValueType.Binary:
                var bytesString = Convert.ToBase64String(value.Binary.ToArray());     // I don't like that ToArray, but it'll do for now.
                builder.Append('[');
                builder.Append(bytesString);
                builder.Append(']');
                break;

            case SdlValueType.Boolean:
                builder.Append(value ? "true" : "false");
                break;

            case SdlValueType.DateTime:
                builder.Append(value.DateTimeOffset.ToUniversalTime().ToString("yyyy/MM/dd HH:mm:ss"));
                break;

            case SdlValueType.Floating:
                var floatValue = value.Floating;
                var formatChar = (floatValue > float.MaxValue || floatValue < float.MinValue)
                                     ? 'f' : 'd';
                builder.Append(Convert.ToString(floatValue));
                builder.Append(formatChar);
                break;

            case SdlValueType.Integer:
                var intValue = value.Integer;
                builder.Append(Convert.ToString(intValue));
                if (intValue > int.MaxValue || intValue < int.MinValue)
                {
                    builder.Append('L');
                }
                break;

            case SdlValueType.Null:
                builder.Append("null");
                break;

            // TODO: Allow customisation of string type.
            case SdlValueType.String:
                builder.Append("`");     // Lazy way out for now
                builder.Append(value.String);
                builder.Append('`');
                break;

            case SdlValueType.TimeSpan:
                builder.Append(value.TimeSpan.ToString(@"dd\d:HH:mm:ss"));
                break;

            default: throw new SdlException($"Unhandled value type: {value.Type}");
            }

            builder.Append(' ');
        }
Beispiel #2
0
        public void VisitNewAttribute(ReadOnlySpan <char> qualifiedName, SdlValue value)
        {
            var nameAsString = qualifiedName.ToString();

            if (this._currentNode.HasAttributeCalled(nameAsString))
            {
                throw new SdlException($"Tag {this._currentNode.QualifiedName} already has an attribute called {nameAsString}");
            }
            this._currentNode.Attributes[nameAsString] = new SdlAttribute(nameAsString, value);
        }
Beispiel #3
0
 public void VisitNewValue(SdlValue value)
 {
 }
Beispiel #4
0
 public void VisitNewAttribute(ReadOnlySpan <char> qualifiedName, SdlValue value)
 {
 }
Beispiel #5
0
 public void VisitNewValue(SdlValue value)
 {
     this._currentNode.Values.Add(value);
 }