Пример #1
0
        //Add a property to the structure
        public virtual void AddProperty(string name, KVValue value)
        {
            if (IsArray)
            {
                // Make up a key for the dictionary
                Properties.Add(Count.ToString(), value);
            }
            else
            {
                Properties.Add(name, value);
            }

            Count++;
        }
Пример #2
0
        //Add a property to the structure
        public virtual void AddProperty(string name, KVValue value)
        {
            if (IsArray)
            {
                // Make up a key for the dictionary
                Properties.Add(Count.ToString(), value);
            }
            else
            {
                Properties.Add(name, value);
            }

            Count++;
        }
Пример #3
0
        //Print a value in the correct representation
        private void PrintValue(IndentedTextWriter writer, KVValue kvValue)
        {
            KVType type      = kvValue.Type;
            object value     = kvValue.Value;
            var    flagValue = kvValue as KVFlaggedValue;

            if (flagValue != null)
            {
                switch (flagValue.Flag)
                {
                case KVFlag.Resource:
                    writer.Write("resource:");
                    break;

                case KVFlag.DeferredResource:
                    writer.Write("deferred_resource:");
                    break;

                default:
                    throw new InvalidOperationException("Trying to print unknown flag");
                }
            }

            switch (type)
            {
            case KVType.OBJECT:
            case KVType.ARRAY:
                ((KVObject)value).Serialize(writer);
                break;

            case KVType.FLAGGED_STRING:
                writer.Write((string)value);
                break;

            case KVType.STRING:
                writer.Write("\"");
                writer.Write(EscapeUnescaped((string)value, '"'));
                writer.Write("\"");
                break;

            case KVType.STRING_MULTI:
                writer.Write("\"\"\"\n");
                writer.Write((string)value);
                writer.Write("\n\"\"\"");
                break;

            case KVType.BOOLEAN:
                writer.Write((bool)value ? "true" : "false");
                break;

            case KVType.DOUBLE:
                writer.Write(((double)value).ToString("#0.000000", CultureInfo.InvariantCulture));
                break;

            case KVType.INTEGER:
                writer.Write((long)value);
                break;

            case KVType.NULL:
                writer.Write("null");
                break;

            default:
                // Unknown type encountered
                throw new InvalidOperationException("Trying to print unknown type.");
            }
        }
Пример #4
0
        //Print a value in the correct representation
        private void PrintValue(IndentedTextWriter writer, KVValue kvValue)
        {
            KVType type = kvValue.Type;
            object value = kvValue.Value;
            var flagValue = kvValue as KVFlaggedValue;
            if (flagValue != null)
            {
                switch (flagValue.Flag)
                {
                    case KVFlag.Resource:
                        writer.Write("resource:");
                        break;
                    case KVFlag.DeferredResource:
                        writer.Write("deferred_resource:");
                        break;
                    default:
                        throw new InvalidOperationException("Trying to print unknown flag");
                }
            }

            switch (type)
            {
                case KVType.OBJECT:
                case KVType.ARRAY:
                    ((KVObject)value).Serialize(writer);
                    break;
                case KVType.FLAGGED_STRING:
                    writer.Write((string)value);
                    break;
                case KVType.STRING:
                    writer.Write("\"");
                    writer.Write(EscapeUnescaped((string)value, '"'));
                    writer.Write("\"");
                    break;
                case KVType.STRING_MULTI:
                    writer.Write("\"\"\"\n");
                    writer.Write((string)value);
                    writer.Write("\n\"\"\"");
                    break;
                case KVType.BOOLEAN:
                    writer.Write((bool)value ? "true" : "false");
                    break;
                case KVType.DOUBLE:
                    writer.Write(((double)value).ToString("#0.000000", CultureInfo.InvariantCulture));
                    break;
                case KVType.INTEGER:
                    writer.Write((long)value);
                    break;
                case KVType.NULL:
                    writer.Write("null");
                    break;
                default:
                    // Unknown type encountered
                    throw new InvalidOperationException("Trying to print unknown type.");
            }
        }