Contains the behavior that is common between node events.
Inheritance: ParsingEvent
        bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType)
        {
            if (currentType == typeof(string) || currentType == typeof(object))
            {
                var scalar = nodeEvent as Scalar;
                if (scalar != null && scalar.IsPlainImplicit)
                {
                    if (Regexes.BooleanLike.IsMatch(scalar.Value))
                    {
                        currentType = typeof(bool);
                        return true;
                    }

                    if (Regexes.IntegerLike.IsMatch(scalar.Value))
                    {
                        currentType = typeof(int);
                        return true;
                    }

                    if (Regexes.DoubleLike.IsMatch(scalar.Value))
                    {
                        currentType = typeof(double);
                        return true;
                    }
                }
            }
            return false;
        }
 bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType)
 {
     if (!string.IsNullOrEmpty(nodeEvent.Tag))
     {
         currentType = Type.GetType(nodeEvent.Tag.Substring(1), true);
         return true;
     }
     return false;
 }
		bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType)
		{
			Type predefinedType;
			if (!string.IsNullOrEmpty(nodeEvent.Tag) && tagMappings.TryGetValue(nodeEvent.Tag, out predefinedType))
			{
				currentType = predefinedType;
				return true;
			}
			return false;
		}
		private Type GetTypeFromEvent(NodeEvent nodeEvent, Type currentType)
		{
			foreach (var typeResolver in typeResolvers)
			{
				if (typeResolver.Resolve(nodeEvent, ref currentType))
				{
					break;
				}
			}
			return currentType;
		}
Beispiel #5
0
		/// <summary>
		/// Loads the specified event.
		/// </summary>
		/// <param name="yamlEvent">The event.</param>
		/// <param name="state">The state of the document.</param>
		internal void Load(NodeEvent yamlEvent, DocumentLoadingState state)
		{
			Tag = yamlEvent.Tag;
			if (yamlEvent.Anchor != null)
			{
				Anchor = yamlEvent.Anchor;
				state.AddAnchor(this);
			}
			Start = yamlEvent.Start;
			End = yamlEvent.End;
		}
 bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType)
 {
     if (!string.IsNullOrEmpty(nodeEvent.Tag))
     {
         // If type could not be loaded, make sure to pass resolving
         // to the next resolver
         currentType = Type.GetType(nodeEvent.Tag.Substring(1), throwOnError: false);
         return currentType != null;
     }
     return false;
 }
 bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType)
 {
     if (!string.IsNullOrEmpty(nodeEvent.Tag))
     {
         // If type could not be loaded, make sure to pass resolving
         // to the next resolver
         try
         {
             currentType = Type.GetType(nodeEvent.Tag.Substring(1), true);
             return true;
         }
         catch { }
     }
     return false;
 }
		private bool NodeIsNull(NodeEvent nodeEvent)
		{
			// http://yaml.org/type/null.html

			if (nodeEvent.Tag == "tag:yaml.org,2002:null")
			{
				return true;
			}

			var scalar = nodeEvent as Scalar;
			if (scalar == null || scalar.Style != Core.ScalarStyle.Plain)
				return false;

			var value = scalar.Value;
			return value == "" || value == "~" || value == "null" || value == "Null" || value == "NULL";
		}
		bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType)
		{
			if (currentType == typeof(object))
			{
				if (nodeEvent is SequenceStart)
				{
					currentType = typeof(List<object>);
					return true;
				}
				if (nodeEvent is MappingStart)
				{
					currentType = typeof(Dictionary<object, object>);
					return true;
				}
			}

			return false;
		}
 public bool Resolve(NodeEvent nodeEvent, ref Type currentType)
 {
     #pragma warning disable 0618 // IYamlSerializable is obsolete
     return typeof(IYamlSerializable).IsAssignableFrom(currentType);
     #pragma warning restore 0618
 }
 public bool Resolve(NodeEvent nodeEvent, ref Type currentType)
 {
     return typeof(IYamlConvertible).IsAssignableFrom(currentType);
 }