예제 #1
0
        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;
        }
예제 #2
0
			protected override void Visit(YamlScalarNode scalar)
			{
				events.Add(new YamlNodeEvent(YamlNodeEventType.Scalar, scalar.Anchor, scalar.Tag, scalar.Value));
			}
예제 #3
0
        /// <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;
            }
        }
예제 #4
0
        /// <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);
            }
        }
예제 #5
0
 public DynamicYamlScalar(YamlScalarNode node)
 {
     this.node = node;
 }
예제 #6
0
 public DynamicYamlScalar(YamlScalarNode node)
 {
     if (node == null) throw new ArgumentNullException(nameof(node));
     this.node = node;
 }
예제 #7
0
 protected override void Visit(YamlScalarNode scalar)
 {
     VisitNode(scalar);
 }
예제 #8
0
 /// <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);
 }
예제 #9
0
 protected override void Visit(YamlScalarNode scalar)
 {
     VisitNode(scalar);
 }
예제 #10
0
 protected override void Visit(YamlScalarNode scalar)
 {
     WriteIndent();
     Console.WriteLine("Visit(YamlScalarNode, {0}, {1}) - {2}", scalar.Anchor, scalar.Tag, scalar.Value);
     ++indent;
 }
예제 #11
0
 protected override void Visited(YamlScalarNode scalar)
 {
     --indent;
     WriteIndent();
     Console.WriteLine("Visited(YamlScalarNode)");
 }
예제 #12
0
 void IYamlVisitor.Visit(YamlScalarNode scalar)
 {
     Visit(scalar);
     Visited(scalar);
 }
예제 #13
0
 /// <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.
 }
예제 #14
0
		void IYamlVisitor.Visit (YamlScalarNode scalar)
		{
			Visit(scalar);
			Visited(scalar);
		}
예제 #15
0
		/// <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.
		}