public override void SerializeNodeValue(double value, string key, IConfigurationSerializationContext <string> context, int index) { if (index != 0) { context.Append(","); } context.Append($@"""{key}"":{value}"); }
public override void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <string> context, int index) { if (index != 0) { context.Append(","); } context.Append($@"""{key}"":""{Sanitize(value)}"""); }
public override void SerializeNodeValue(bool value, string key, IConfigurationSerializationContext <string> context, int index) { if (index != 0) { context.Append(","); } context.Append($@"""{key}"":{value.ToString().ToLower()}"); }
public override void SerializeBlockBegin(IConfigurationSerializationContext <string> context, int index) { if (index != 0) { context.Append(","); } context.Append($@"""{context.GetCurrentScope()}"": {{"); }
/// <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(); } }
/// <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; } }
/// <summary> /// Write the header to the serialized stream. /// </summary> /// <param name="context">The serialization context.</param> public virtual void SerializeFooter(IConfigurationSerializationContext <T> context) { return; }
/// <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);
public override void SerializeFooter(IConfigurationSerializationContext <string> context) { context.Append("}"); }
public override void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <string> context, int index) { context.AppendLine($"<{key}>{value}</{key}>"); }
public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index) { // todo: sanitize context.AppendLine($"</{context.GetCurrentScope()}>"); }
public override void SerializeNodeValue(string value, string key, IConfigurationSerializationContext <string> context, int index) { context.AppendLine($"{key}={value}"); }
public override void SerializeBlockBegin(IConfigurationSerializationContext <string> context, int index) { context.AppendLine($"[{String.Join('.', context.GetFullScope())}]"); }
public override void SerializerNodeValue(ControllerElement controllerElementValue, string value, string key, IConfigurationSerializationContext <string> context, int index) { if (index != 0) { context.Append(","); } context.Append($@"""{key}"":""{value}"""); }
public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index) { context.Append("}"); }
/// <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);
/// <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); }
public override void SerializeBlockEnd(IConfigurationSerializationContext <string> context, int index) { return; }
/// <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); }
public override void SerializeFooter(IConfigurationSerializationContext <string> context) { context.AppendLine($"</{this.RootElementName}>"); }
/// <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); }
public override void SerializeNodeValue(double value, string key, IConfigurationSerializationContext <string> context, int index) { context.AppendLine($"<{key}>{value}</{key}>"); }
/// <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);
public static void AppendLine(this IConfigurationSerializationContext <string> @this, string content) { @this.Append($"{content}{Environment.NewLine}"); }
/// <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); }