private Type TypeFromTag(string tag) { if (tag.StartsWith(YamlNode.DefaultTagPrefix)) { switch (tag.Substring(YamlNode.DefaultTagPrefix.Length)) { case "str": return(typeof(string)); case "int": return(typeof(Int32)); case "null": return(typeof(object)); case "bool": return(typeof(bool)); case "float": return(typeof(double)); case "seq": case "map": return(null); default: throw new NotImplementedException("tag [{0}] is not supported".DoFormat(tag)); } } return(context.ResolveType(tag.Substring(1))); }
public IYamlTypeConverter TryCreate(SerializerContext context, Type type) { var attrs = type.GetCustomAttributes(typeof (TypeConverterAttribute), true); if (attrs.Length > 0) { var converterAttr = (TypeConverterAttribute)attrs[0]; // What is the difference between these two conditions? var converterType = context.ResolveType(converterAttr.ConverterTypeName); var typeCovnerter = Activator.CreateInstance(converterType) as TypeConverter; if (typeCovnerter != null) { return new LegacyTypeConverter(typeCovnerter); } } return null; }
public IYamlSerializable TryCreate(SerializerContext context, Type type) { var attribute = type.GetAttribute<YamlSerializableAttribute>(); if (attribute == null) { return null; } var typeName = attribute.SerializableTypeName; var serializableType = context.ResolveType(typeName); if (serializableType == null) { throw new InvalidOperationException(string.Format("Unable to find serializable type [{0}] from current and registered assemblies", typeName)); } if (!typeof(IYamlSerializable).IsAssignableFrom(serializableType)) { throw new InvalidOperationException(string.Format("Serializable type [{0}] is not a IYamlSerializable", typeName)); } return (IYamlSerializable)Activator.CreateInstance(serializableType); }
public IYamlSerializable TryCreate(SerializerContext context, Type type) { var attribute = type.GetAttribute <YamlSerializableAttribute>(); if (attribute == null) { return(null); } var typeName = attribute.SerializableTypeName; var serializableType = context.ResolveType(typeName); if (serializableType == null) { throw new InvalidOperationException(string.Format("Unable to find serializable type [{0}] from current and registered assemblies", typeName)); } if (!typeof(IYamlSerializable).IsAssignableFrom(serializableType)) { throw new InvalidOperationException(string.Format("Serializable type [{0}] is not a IYamlSerializable", typeName)); } return((IYamlSerializable)Activator.CreateInstance(serializableType)); }