public override bool TrySetMember(SetMemberBinder binder, object value) { var key = new YamlScalarNode(binder.Name); if (value is DynamicYamlEmpty) node.Children.Remove(key); else node.Children[key] = ConvertFromDynamic(value); return true; }
protected override void Visit(YamlScalarNode scalar) { events.Add(new YamlNodeEvent(YamlNodeEventType.Scalar, scalar.Anchor, scalar.Tag, scalar.Value)); }
/// <summary> /// Removes an override information from the specified member. /// </summary> /// <param name="key">The member name</param> public void RemoveOverride(string key) { if (overrides == null) { return; } // If we have an override we need to remove the override text from the name if (overrides.Remove(key)) { var propertyName = GetRealPropertyName(key); var previousKey = new YamlScalarNode(GetRealPropertyName(propertyName)); int index = node.Children.IndexOf(previousKey); var previousMemberValue = node.Children[index].Value; node.Children.RemoveAt(index); node.Children.Insert(index, new YamlScalarNode(key), previousMemberValue); keyMapping[key] = key; } }
/// <summary> /// Sets the override type for the specified member. /// </summary> /// <param name="key">The member name to setup an override</param> /// <param name="type">Type of the override</param> public void SetOverride(string key, OverrideType type) { if (key == null) throw new ArgumentNullException(nameof(key)); YamlNode previousMemberKey = null; YamlNode previousMemberValue = null; if (keyMapping == null) { keyMapping = new Dictionary<string, string>(); } else { string previousMemberName; if (keyMapping.TryGetValue(key, out previousMemberName)) { previousMemberKey = new YamlScalarNode(previousMemberName); node.Children.TryGetValue(previousMemberKey, out previousMemberValue); } keyMapping.Remove(key); } if (overrides == null) { overrides = new Dictionary<string, OverrideType>(); } else { overrides.Remove(key); } // New member name var newMemberName = type == OverrideType.Base ? key : $"{key}{type.ToText()}"; keyMapping[key] = newMemberName; overrides[key] = type; // Remap the original YAML node with the override type if (previousMemberKey != null) { int index = node.Children.IndexOf(previousMemberKey); node.Children.RemoveAt(index); node.Children.Insert(index, new YamlScalarNode(newMemberName), previousMemberValue); } }
public DynamicYamlScalar(YamlScalarNode node) { this.node = node; }
public DynamicYamlScalar(YamlScalarNode node) { if (node == null) throw new ArgumentNullException(nameof(node)); this.node = node; }
protected override void Visit(YamlScalarNode scalar) { VisitNode(scalar); }
/// <summary> /// Initializes a new instance of the <see cref="YamlDocument"/> class with a single scalar node. /// </summary> public YamlDocument(string rootNode) { RootNode = new YamlScalarNode(rootNode); }
protected override void Visit(YamlScalarNode scalar) { WriteIndent(); Console.WriteLine("Visit(YamlScalarNode, {0}, {1}) - {2}", scalar.Anchor, scalar.Tag, scalar.Value); ++indent; }
protected override void Visited(YamlScalarNode scalar) { --indent; WriteIndent(); Console.WriteLine("Visited(YamlScalarNode)"); }
void IYamlVisitor.Visit(YamlScalarNode scalar) { Visit(scalar); Visited(scalar); }
/// <summary> /// Called after this object finishes visiting a <see cref="YamlScalarNode"/>. /// </summary> /// <param name="scalar"> /// The <see cref="YamlScalarNode"/> that has been visited. /// </param> protected virtual void Visited(YamlScalarNode scalar) { // Do nothing. }
void IYamlVisitor.Visit (YamlScalarNode scalar) { Visit(scalar); Visited(scalar); }
/// <summary> /// Called after this object finishes visiting a <see cref="YamlScalarNode"/>. /// </summary> /// <param name="scalar"> /// The <see cref="YamlScalarNode"/> that has been visited. /// </param> protected virtual void Visited (YamlScalarNode scalar) { // Do nothing. }