コード例 #1
0
 public override void SerializeNodeValue(double value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":{value}");
 }
コード例 #2
0
 public override void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":""{Sanitize(value)}""");
 }
コード例 #3
0
 public override void SerializeNodeValue(bool value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":{value.ToString().ToLower()}");
 }
コード例 #4
0
 public override void SerializeBlockBegin(IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{context.GetCurrentScope()}"": {{");
 }
コード例 #5
0
        /// <summary>
        /// Serializes a list of configuration nodes.
        ///
        /// For each child node to be serialized, the index should be incremented. Serializing a list node will
        /// enter a new block, and thus block headers and footers are written at the beginning and end of
        /// serialization of this node respectively.
        /// </summary>
        /// <param name="node">The list of configuration nodes represented as a <see cref="ListConfigurationNode"/></param>
        /// <param name="context">The serialization context.</param>
        /// <param name="index">The position or index of the given node within the current block in the context.</param>
        protected void SerializeNode(ListConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
        {
            // Ignore pseudo-targets
            if (!node.Key.StartsWith("#"))
            {
                context.EnterScope(node.Key);
                this.SerializeBlockBegin(context, index);
            }

            int childIndex = 0;

            foreach (var childNode in node.Value)
            {
                this.SerializeNode(childNode, context, childIndex);
                childIndex++;
            }

            if (!node.Key.StartsWith("#"))
            {
                this.SerializeBlockEnd(context, index);
                context.ExitScope();
            }
        }
コード例 #6
0
        /// <summary>
        /// Serialize a <see cref="IAbstractConfigurationNode"/> with the given context.
        /// </summary>
        /// <param name="node">The node to serialize.</param>
        /// <param name="context">The serialization context.</param>
        /// <param name="index">The position or index of the given node within the current block in the context.</param>
        public void SerializeNode(IAbstractConfigurationNode node,
                                  IConfigurationSerializationContext <T> context, int index = 0)
        {
            switch (node)
            {
            case ListConfigurationNode listNode:
                this.SerializeNode(listNode, context, index);
                break;

            case StringConfigurationNode stringNode:
                this.SerializeNode(stringNode, context, index);
                break;

            case BooleanConfigurationNode boolNode:
                this.SerializeNode(boolNode, context, index);
                break;

            case IntegralConfigurationNode intNode:
                this.SerializeNode(intNode, context, index);
                break;

            case DecimalConfigurationNode decNode:
                this.SerializeNode(decNode, context, index);
                break;

            case DeviceCapabilityElementConfigurationNode ctrlNode:
                this.SerializeNode(ctrlNode, context, index);
                break;

            case EnumConfigurationNode enumNode:
                this.SerializeNode(enumNode, context, index);
                break;

            default:
                break;
            }
        }
コード例 #7
0
 /// <summary>
 /// Write the header to the serialized stream.
 /// </summary>
 /// <param name="context">The serialization context.</param>
 public virtual void SerializeFooter(IConfigurationSerializationContext <T> context)
 {
     return;
 }
コード例 #8
0
 /// <summary>
 /// Serializes the value of a <see cref="EnumConfigurationNode"/>. Override this when implementing a serializer.
 /// </summary>
 /// <param name="controllerElementValue">The value of the node</param>
 /// <param name="value">
 /// The raw value of the node as the string representation of the element consistent with the
 /// <see cref="IDeviceInputMapping"/> the syntax tree was originally serialized with.</param>
 /// <param name="key">The key of the node.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 public abstract void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <T> context, int index);
コード例 #9
0
 public override void SerializeFooter(IConfigurationSerializationContext <string> context)
 {
     context.Append("}");
 }
コード例 #10
0
 public override void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"<{key}>{value}</{key}>");
 }
コード例 #11
0
 public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index)
 {
     // todo: sanitize
     context.AppendLine($"</{context.GetCurrentScope()}>");
 }
コード例 #12
0
 public override void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"{key}={value}");
 }
コード例 #13
0
 public override void SerializeBlockBegin(IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"[{String.Join('.', context.GetFullScope())}]");
 }
コード例 #14
0
 public override void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     if (index != 0)
     {
         context.Append(",");
     }
     context.Append($@"""{key}"":""{value}""");
 }
コード例 #15
0
 public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index)
 {
     context.Append("}");
 }
コード例 #16
0
 /// <summary>
 /// Serialize a marker or footer where a block or section ends in the serialized stream.
 /// </summary>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 public abstract void SerializeBlockEnd(IConfigurationSerializationContext <T> context, int index);
コード例 #17
0
 /// <summary>
 /// Serializes a configuration node that encapsulates a decimal value, implemented as a <see cref="double"/>.
 ///
 /// Contrary to the name, this is not implemented as a <see cref="decimal"/>, and IEEE 754 floating point semantics
 /// for double precision floating point numbers should be taken into account.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(DecimalConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue(node.Value, node.Key, context, index);
 }
コード例 #18
0
 public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index)
 {
     return;
 }
コード例 #19
0
 /// <summary>
 /// Serializes a configuration node that encapsulates an <see cref="Enum"/> value.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(EnumConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue((node as AbstractConfigurationNode <Enum>).Value, node.Value, node.Key, context, index);
 }
コード例 #20
0
 public override void SerializeFooter(IConfigurationSerializationContext <string> context)
 {
     context.AppendLine($"</{this.RootElementName}>");
 }
コード例 #21
0
 /// <summary>
 /// Serializes a configuration node that encapsulates a <see cref="ControllerElement"/>.
 ///
 /// This is only used when serializing syntax trees that came from <see cref="IInputTemplate"/>.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(DeviceCapabilityElementConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue((node as AbstractConfigurationNode <DeviceCapability>).Value, node.Value, node.Key, context, index);
 }
コード例 #22
0
 public override void SerializeNodeValue(double value, string key, IConfigurationSerializationContext <string> context, int index)
 {
     context.AppendLine($"<{key}>{value}</{key}>");
 }
コード例 #23
0
 /// <summary>
 /// Serializes the value of a <see cref="StringConfigurationNode"/>. Override this when implementing a serializer.
 /// </summary>
 /// <param name="value">The raw value of the node.</param>
 /// <param name="key">The key of the node.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 public abstract void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <T> context, int index);
コード例 #24
0
 public static void AppendLine(this IConfigurationSerializationContext <string> @this, string content)
 {
     @this.Append($"{content}{Environment.NewLine}");
 }
コード例 #25
0
 /// <summary>
 /// Serializes a configuration node that encapsulates a <see cref="ControllerElement"/>.
 ///
 /// This is only used when serializing syntax trees that came from <see cref="IInputTemplate"/>.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="context">The serialization context.</param>
 /// <param name="index">The position or index of the given node within the current block in the context.</param>
 protected void SerializeNode(ControllerElementConfigurationNode node, IConfigurationSerializationContext <T> context, int index)
 {
     this.SerializeNodeValue((node as AbstractConfigurationNode <ControllerElement>).Value, node.Value, node.Key, context, index);
 }