public void TestJsonSchemaCommon(IYamlSchema schema) { Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar(null, null, "true", ScalarStyle.DoubleQuoted, false, false))); Assert.Equal(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.Equal(JsonSchema.NullShortTag, schema.GetDefaultTag(new Scalar("null"))); Assert.Equal(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("5"))); Assert.Equal(JsonSchema.FloatShortTag, schema.GetDefaultTag(new Scalar("5.5"))); Assert.Equal(JsonSchema.NullLongTag, schema.ExpandTag("!!null")); Assert.Equal(JsonSchema.BoolLongTag, schema.ExpandTag("!!bool")); Assert.Equal(JsonSchema.IntLongTag, schema.ExpandTag("!!int")); Assert.Equal(JsonSchema.FloatLongTag, schema.ExpandTag("!!float")); Assert.Equal("!!null", schema.ShortenTag(JsonSchema.NullLongTag)); Assert.Equal("!!bool", schema.ShortenTag(JsonSchema.BoolLongTag)); Assert.Equal("!!int", schema.ShortenTag(JsonSchema.IntLongTag)); Assert.Equal("!!float", schema.ShortenTag(JsonSchema.FloatLongTag)); TryParse(schema, "null", JsonSchema.NullShortTag, null); TryParse(schema, "true", JsonSchema.BoolShortTag, true); TryParse(schema, "false", JsonSchema.BoolShortTag, false); TryParse(schema, "5", JsonSchema.IntShortTag, 5); TryParse(schema, "5.5", JsonSchema.FloatShortTag, 5.5); TryParse(schema, ".inf", JsonSchema.FloatShortTag, double.PositiveInfinity); }
/// <summary> /// Initializes a new instance of the <see cref="SerializerSettings" /> class. /// </summary> public SerializerSettings(IYamlSchema schema) { PreferredIndent = 2; IndentLess = false; EmitAlias = true; EmitTags = true; AllowErrors = false; ResetAlias = true; SortKeyForMapping = true; EmitJsonComptible = false; EmitCapacityForList = false; SpecialCollectionMember = "~Items"; LimitPrimitiveFlowSequence = 0; DefaultStyle = YamlStyle.Block; this.schema = schema ?? new CoreSchema(); AssemblyRegistry = new AssemblyRegistry(Schema); attributeRegistry = new AttributeRegistry(); ObjectFactory = new DefaultObjectFactory(); ObjectSerializerBackend = new DefaultObjectSerializerBackend(); ComparerForKeySorting = new DefaultKeyComparer(); NamingConvention = new DefaultNamingConvention(); // Register default mapping for map and seq AssemblyRegistry.RegisterTagMapping("!!map", typeof(IDictionary <object, object>), false); AssemblyRegistry.RegisterTagMapping("!!seq", typeof(IList <object>), false); }
/// <summary> /// Initializes a new instance of the <see cref="TagTypeRegistry"/> class. /// </summary> public TagTypeRegistry(IYamlSchema schema) { if (schema == null) throw new ArgumentNullException("schema"); this.schema = schema; tagToType = new Dictionary<string, Type>(); typeToTag = new Dictionary<Type, string>(); lookupAssemblies = new List<Assembly>(); }
private void TryParse(IYamlSchema schema, string scalar, string expectedShortTag, object expectedValue) { string tag; object value; Assert.True(schema.TryParse(new Scalar(scalar), true, out tag, out value)); Assert.Equal(expectedShortTag, tag); Assert.Equal(expectedValue, value); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyRegistry"/> class. /// </summary> public AssemblyRegistry(IYamlSchema schema) { if (schema == null) throw new ArgumentNullException("schema"); this.schema = schema; tagToType = new Dictionary<string, MappedType>(); typeToTag = new Dictionary<Type, string>(); lookupAssemblies = new List<Assembly>(); SerializableFactories = new List<IYamlSerializableFactory>(); }
public YamlValue(object value, IYamlSchema schema = null) { var valueString = PrimitiveSerializer.ConvertValue(value); if (schema == null) { schema = CoreSchema.Instance; } Scalar = new Scalar(schema.GetDefaultTag(value.GetType()), valueString); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyRegistry"/> class. /// </summary> public AssemblyRegistry(IYamlSchema schema) { if (schema == null) { throw new ArgumentNullException("schema"); } this.schema = schema; tagToType = new Dictionary <string, Type>(); typeToTag = new Dictionary <Type, string>(); lookupAssemblies = new List <Assembly>(); SerializableFactories = new List <IYamlSerializableFactory>(); }
/// <summary> /// Initializes a new instance of the <see cref="YamlAssemblyRegistry"/> class. /// </summary> public YamlAssemblyRegistry(IYamlSchema schema) { if (schema == null) { throw new ArgumentNullException(nameof(schema)); } this.schema = schema; tagToType = new Dictionary <string, MappedType>(); typeToTag = new Dictionary <Type, string>(); lookupAssemblies = new List <Assembly> { typeof(int).Assembly }; SerializableFactories = new List <IYamlSerializableFactory>(); }
public void TestCoreSchemaCommon(IYamlSchema schema) { TestJsonSchemaCommon(schema); // Core schema is accepting plain string Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("boom"))); Assert.Equal(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("True"))); Assert.Equal(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("TRUE"))); Assert.Equal(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("0x10"))); TryParse(schema, "TRUE", JsonSchema.BoolShortTag, true); TryParse(schema, "FALSE", JsonSchema.BoolShortTag, false); TryParse(schema, "0x10", JsonSchema.IntShortTag, 16); TryParse(schema, "16", JsonSchema.IntShortTag, 16); }
public void TestCoreSchemaCommon(IYamlSchema schema) { TestJsonSchemaCommon(schema); // Core schema is accepting plain string Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("boom"))); Assert.AreEqual(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("True"))); Assert.AreEqual(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("TRUE"))); Assert.AreEqual(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("0x10"))); TryParse(schema, "TRUE", JsonSchema.BoolShortTag, true); TryParse(schema, "FALSE", JsonSchema.BoolShortTag, false); TryParse(schema, "0x10", JsonSchema.IntShortTag, 16); TryParse(schema, "16", JsonSchema.IntShortTag, 16); }
public void TestFailsafeSchemaCommon(IYamlSchema schema) { Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.Equal(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("custom", "boom"))); Assert.Equal(FailsafeSchema.MapShortTag, schema.GetDefaultTag(new MappingStart())); Assert.Equal(FailsafeSchema.SeqShortTag, schema.GetDefaultTag(new SequenceStart())); Assert.Equal(FailsafeSchema.MapLongTag, schema.ExpandTag("!!map")); Assert.Equal(FailsafeSchema.SeqLongTag, schema.ExpandTag("!!seq")); Assert.Equal(SchemaBase.StrLongTag, schema.ExpandTag("!!str")); Assert.Equal("!!map", schema.ShortenTag(FailsafeSchema.MapLongTag)); Assert.Equal("!!seq", schema.ShortenTag(FailsafeSchema.SeqLongTag)); Assert.Equal("!!str", schema.ShortenTag(SchemaBase.StrLongTag)); TryParse(schema, "true", SchemaBase.StrShortTag, "true"); }
/// <summary> /// Initializes a new instance of the <see cref="SerializerSettings" /> class. /// </summary> public SerializerSettings(IYamlSchema schema) { PreferredIndent = 2; IndentLess = false; EmitAlias = true; EmitTags = true; SortKeyForMapping = true; EmitJsonComptible = false; EmitCapacityForList = false; SpecialCollectionMember = "~Items"; LimitPrimitiveFlowSequence = 0; DefaultStyle = DataStyle.Normal; this.schema = schema ?? new CoreSchema(); AssemblyRegistry = new YamlAssemblyRegistry(Schema); attributeRegistry = new AttributeRegistry(); ObjectFactory = new DefaultObjectFactory(); ObjectSerializerBackend = new DefaultObjectSerializerBackend(); ComparerForKeySorting = new DefaultKeyComparer(); NamingConvention = new DefaultNamingConvention(); SerializerFactorySelector = new ProfileSerializerFactorySelector(YamlSerializerFactoryAttribute.Default); // Register default mapping for map and seq AssemblyRegistry.RegisterTagMapping("!!map", typeof(IDictionary<object, object>), false); AssemblyRegistry.RegisterTagMapping("!!seq", typeof(IList<object>), false); }
public void TestFailsafeSchemaCommon(IYamlSchema schema) { Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar("custom", "boom"))); Assert.AreEqual(FailsafeSchema.MapShortTag, schema.GetDefaultTag(new MappingStart())); Assert.AreEqual(FailsafeSchema.SeqShortTag, schema.GetDefaultTag(new SequenceStart())); Assert.AreEqual(FailsafeSchema.MapLongTag, schema.ExpandTag("!!map")); Assert.AreEqual(FailsafeSchema.SeqLongTag, schema.ExpandTag("!!seq")); Assert.AreEqual(SchemaBase.StrLongTag, schema.ExpandTag("!!str")); Assert.AreEqual("!!map", schema.ShortenTag(FailsafeSchema.MapLongTag)); Assert.AreEqual("!!seq", schema.ShortenTag(FailsafeSchema.SeqLongTag)); Assert.AreEqual("!!str", schema.ShortenTag(SchemaBase.StrLongTag)); TryParse(schema, "true", SchemaBase.StrShortTag, "true"); }
private void TryParse(IYamlSchema schema, string scalar, string expectedShortTag, object expectedValue) { string tag; object value; Assert.True(schema.TryParse(new Scalar(scalar), true, out tag, out value)); Assert.AreEqual(expectedShortTag, tag); Assert.AreEqual(expectedValue, value); }
public void TestJsonSchemaCommon(IYamlSchema schema) { Assert.AreEqual(SchemaBase.StrShortTag, schema.GetDefaultTag(new Scalar(null, null, "true", ScalarStyle.DoubleQuoted, false, false))); Assert.AreEqual(JsonSchema.BoolShortTag, schema.GetDefaultTag(new Scalar("true"))); Assert.AreEqual(JsonSchema.NullShortTag, schema.GetDefaultTag(new Scalar("null"))); Assert.AreEqual(JsonSchema.IntShortTag, schema.GetDefaultTag(new Scalar("5"))); Assert.AreEqual(JsonSchema.FloatShortTag, schema.GetDefaultTag(new Scalar("5.5"))); Assert.AreEqual(JsonSchema.NullLongTag, schema.ExpandTag("!!null")); Assert.AreEqual(JsonSchema.BoolLongTag, schema.ExpandTag("!!bool")); Assert.AreEqual(JsonSchema.IntLongTag, schema.ExpandTag("!!int")); Assert.AreEqual(JsonSchema.FloatLongTag, schema.ExpandTag("!!float")); Assert.AreEqual("!!null", schema.ShortenTag(JsonSchema.NullLongTag)); Assert.AreEqual("!!bool", schema.ShortenTag(JsonSchema.BoolLongTag)); Assert.AreEqual("!!int", schema.ShortenTag(JsonSchema.IntLongTag)); Assert.AreEqual("!!float", schema.ShortenTag(JsonSchema.FloatLongTag)); TryParse(schema, "null", JsonSchema.NullShortTag, null); TryParse(schema, "true", JsonSchema.BoolShortTag, true); TryParse(schema, "false", JsonSchema.BoolShortTag, false); TryParse(schema, "5", JsonSchema.IntShortTag, 5); TryParse(schema, "5.5", JsonSchema.FloatShortTag, 5.5); TryParse(schema, ".inf", JsonSchema.FloatShortTag, double.PositiveInfinity); }
/// <summary> /// Initializes a new instance of the <see cref="SerializerSettings" /> class. /// </summary> public SerializerSettings(IYamlSchema schema) { PreferredIndent = 2; IndentLess = false; EmitAlias = true; EmitTags = true; SortKeyForMapping = true; EmitJsonComptible = false; EmitCapacityForList = false; SpecialCollectionMember = "~Items"; LimitPrimitiveFlowSequence = 0; DefaultStyle = YamlStyle.Block; this.schema = schema ?? new CoreSchema(); tagTypeRegistry = new TagTypeRegistry(Schema); attributeRegistry = new AttributeRegistry(); ObjectFactory = new DefaultObjectFactory(); ObjectSerializerBackend = new DefaultObjectSerializerBackend(); // Register default mapping for map and seq tagTypeRegistry.RegisterTagMapping("!!map", typeof(IDictionary<object, object>)); tagTypeRegistry.RegisterTagMapping("!!seq", typeof(IList<object>)); }