public override bool Enter(IObjectDescriptor value, IEmitter context)
        {
            IYamlTypeConverter yamlTypeConverter = typeConverters.FirstOrDefault((IYamlTypeConverter t) => t.Accepts(value.Type));

            if (yamlTypeConverter != null)
            {
                yamlTypeConverter.WriteYaml(context, value.Value, value.Type);
                return(false);
            }
            IYamlConvertible yamlConvertible = value.Value as IYamlConvertible;

            if (yamlConvertible != null)
            {
                yamlConvertible.Write(context, nestedObjectSerializer);
                return(false);
            }
            IYamlSerializable yamlSerializable = value.Value as IYamlSerializable;

            if (yamlSerializable != null)
            {
                yamlSerializable.WriteYaml(context);
                return(false);
            }
            return(base.Enter(value, context));
        }
Example #2
0
 public bool Deserialize(IParser parser, Type expectedType, Func <IParser, Type, object> nestedObjectDeserializer, out object value)
 {
     if (typeof(IYamlConvertible).IsAssignableFrom(expectedType))
     {
         IYamlConvertible yamlConvertible = (IYamlConvertible)objectFactory.Create(expectedType);
         yamlConvertible.Read(parser, expectedType, (Type type) => nestedObjectDeserializer(parser, type));
         value = yamlConvertible;
         return(true);
     }
     value = null;
     return(false);
 }
		bool IObjectGraphVisitor<Nothing>.Enter(IObjectDescriptor value, Nothing context)
		{
			IYamlTypeConverter yamlTypeConverter = typeConverters.FirstOrDefault((IYamlTypeConverter t) => t.Accepts(value.Type));
			if (yamlTypeConverter != null)
			{
				return false;
			}
			IYamlConvertible yamlConvertible = value.Value as IYamlConvertible;
			if (yamlConvertible != null)
			{
				return false;
			}
			IYamlSerializable yamlSerializable = value.Value as IYamlSerializable;
			if (yamlSerializable != null)
			{
				return false;
			}
			return Enter(value);
		}