private void AssignTypeIfDifferent(ObjectEventInfo eventInfo)
 {
     if (this._assignTypeWhenDifferent && ((eventInfo.Source.Value != null) && !ReferenceEquals(eventInfo.Source.Type, eventInfo.Source.StaticType)))
     {
         eventInfo.Tag = "!" + eventInfo.Source.Type.AssemblyQualifiedName;
     }
 }
 private void AssignTypeIfDifferent(ObjectEventInfo eventInfo)
 {
     if (_assignTypeWhenDifferent && eventInfo.Source.Value != null)
     {
         if (eventInfo.Source.Type != eventInfo.Source.StaticType)
         {
             eventInfo.Tag = "!" + eventInfo.Source.Type.AssemblyQualifiedName;
         }
     }
 }
        private void AssignTypeIfNeeded(ObjectEventInfo eventInfo)
        {
            string value = null;

            if (tagMappings.TryGetValue(eventInfo.Source.Type, out value))
            {
                eventInfo.Tag = value;
            }
            else if (requireTagWhenStaticAndActualTypesAreDifferent && eventInfo.Source.Value != null && eventInfo.Source.Type != eventInfo.Source.StaticType)
            {
                throw new YamlException("Cannot serialize type " + eventInfo.Source.Type.FullName + " where a " + eventInfo.Source.StaticType.FullName + " was expected because no tag mapping has been registered for " + eventInfo.Source.Type.FullName + "which means that it won't be possible to deserialize the document.\nRegister a tag mapping using the SerializerBuilder.WithTagMapping method.\n\nE.g: builder.WithTagMapping(\"!" + eventInfo.Source.Type.Name + "\", typeof({" + eventInfo.Source.Type.FullName + "}));");
            }
        }
 private void AssignTypeIfNeeded(ObjectEventInfo eventInfo)
 {
     if (tagMappings.TryGetValue(eventInfo.Source.Type, out string tag))
     {
         eventInfo.Tag = tag;
     }
     else if (requireTagWhenStaticAndActualTypesAreDifferent && eventInfo.Source.Value != null && eventInfo.Source.Type != eventInfo.Source.StaticType)
     {
         throw new YamlException(
                   $"Cannot serialize type '{eventInfo.Source.Type.FullName}' where a '{eventInfo.Source.StaticType.FullName}' was expected " +
                   $"because no tag mapping has been registered for '{eventInfo.Source.Type.FullName}', " +
                   $"which means that it won't be possible to deserialize the document.\n" +
                   $"Register a tag mapping using the SerializerBuilder.WithTagMapping method.\n\n" +
                   $"E.g: builder.WithTagMapping(\"!{eventInfo.Source.Type.Name}\", typeof({eventInfo.Source.Type.FullName}));"
                   );
     }
 }
Пример #5
0
        private void AssignTypeIfDifferent(ObjectEventInfo eventInfo)
        {
            if (eventInfo.Source.Value == null)
            {
                return;
            }
            if (eventInfo.Source.Type == eventInfo.Source.StaticType)
            {
                return;
            }

            var tagRes =
                _Tags.Where(_ => _.Key.IsAssignableFrom(eventInfo.Source.Type)).Select(_ => _.Value).ToArray();

            if (tagRes.Any())
            {
                eventInfo.Tag = "!!" + tagRes.First();
            }
        }
		private void AssignTypeIfDifferent(ObjectEventInfo eventInfo)
		{
			if (_assignTypeWhenDifferent && eventInfo.Source.Value != null)
			{
				if (eventInfo.Source.Type != eventInfo.Source.StaticType)
				{
					eventInfo.Tag = "!" + eventInfo.Source.Type.AssemblyQualifiedName;
				}
			}
		}