Beispiel #1
0
        IContentReader IContentReaderFactory.TryCreate(Type type)
        {
#if W8CORE
            var attributes = attributeRegistry.GetAttributes(type.GetTypeInfo(), false);
#else
            var attributes = attributeRegistry.GetAttributes(type, false);
#endif
            if (attributes.Count > 0)
            {
                foreach (var attribute in attributes)
                {
                    if (attribute is YamlTagAttribute)
                    {
                        // Make sure that the assembly for type is registered for loading
#if W8CORE
                        yamlSettings.RegisterAssembly(type.GetTypeInfo().Assembly);
#else
                        yamlSettings.RegisterAssembly(type.Assembly);
#endif
                        return(this);
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        private static Serializer CreateSerializer(ref Serializer localSerializer, bool generateIds)
        {
            if (localSerializer == null)
            {
                // var clock = Stopwatch.StartNew();

                var config = new SerializerSettings()
                {
                    EmitAlias = false,
                    LimitPrimitiveFlowSequence = 0,
                    Attributes        = new AtributeRegistryFilter(),
                    PreferredIndent   = 4,
                    EmitShortTypeName = true,
                };

                if (generateIds)
                {
                    config.Attributes.PrepareMembersCallback += PrepareMembersCallback;
                }

                for (int index = RegisteredAssemblies.Count - 1; index >= 0; index--)
                {
                    var registeredAssembly = RegisteredAssemblies[index];
                    config.RegisterAssembly(registeredAssembly);
                }

                localSerializer = new Serializer(config);
                localSerializer.Settings.ObjectSerializerBackend = new CustomObjectSerializerBackend(TypeDescriptorFactory.Default);

                // Log.Info("New YAML serializer created in {0}ms", clock.ElapsedMilliseconds);
            }

            return(localSerializer);
        }
Beispiel #3
0
        private static Serializer CreateSerializer(bool keepOnlySealedOverrides, ref Serializer localSerializer)
        {
            if (localSerializer == null)
            {
                // var clock = Stopwatch.StartNew();

                var config = new SerializerSettings()
                {
                    EmitAlias = false,
                    LimitPrimitiveFlowSequence = 0,
                    Attributes        = new AtributeRegistryFilter(),
                    PreferredIndent   = 4,
                    EmitShortTypeName = true,
                };

                for (int index = RegisteredAssemblies.Count - 1; index >= 0; index--)
                {
                    var registeredAssembly = RegisteredAssemblies[index];
                    config.RegisterAssembly(registeredAssembly);
                }

                localSerializer = new Serializer(config);
                localSerializer.Settings.ObjectSerializerBackend = new OverrideKeyMappingTransform(TypeDescriptorFactory.Default, keepOnlySealedOverrides);

                // Log.Info("New YAML serializer created in {0}ms", clock.ElapsedMilliseconds);
            }

            return(localSerializer);
        }
Beispiel #4
0
        private void Roundtrip <T>(SerializerSettings settings)
            where T : new()
        {
            settings.RegisterAssembly(typeof(SerializationTests).Assembly);
            var serializer = new Serializer(settings);

            var buffer   = new StringWriter();
            var original = new T();

            serializer.Serialize(buffer, original);

            Dump.WriteLine(buffer);

            var bufferText = buffer.ToString();
            var copy       = serializer.Deserialize <T>(bufferText);

            foreach (var property in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.CanRead && property.CanWrite)
                {
                    Assert.AreEqual(
                        property.GetValue(original, null),
                        property.GetValue(copy, null));
                }
            }
        }
Beispiel #5
0
        public void RoundtripWithDefaults()
        {
            var settings = new SerializerSettings()
            {
                EmitDefaultValues = true
            };

            settings.RegisterAssembly(typeof(SerializationTests).Assembly);
            var serializer = new Serializer(settings);

            var buffer   = new StringWriter();
            var original = new X();

            serializer.Serialize(buffer, original);

            Dump.WriteLine(buffer);

            var bufferText = buffer.ToString();
            var copy       = serializer.Deserialize <X>(bufferText);

            foreach (var property in typeof(X).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.CanRead && property.CanWrite)
                {
                    Assert.AreEqual(
                        property.GetValue(original, null),
                        property.GetValue(copy, null));
                }
            }
        }
Beispiel #6
0
        public void RoundtripNoPrivateSetters()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(SerializationTests).Assembly);
            var serializer = new Serializer(settings);

            var modified = new PrivateSetters();

            modified.ModifyPrivateProperties();

            var buffer = new StringWriter();

            serializer.Serialize(buffer, modified);

            Dump.WriteLine(buffer);

            var deserialized = serializer.Deserialize <PrivateSetters>(buffer.ToString());

            foreach (var property in typeof(PrivateSetters).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.CanRead && property.GetSetMethod(false) == null)
                {
                    Console.WriteLine("Property " + property.Name + " / " + property.GetValue(modified, null) + " / " + property.GetValue(deserialized, null));

                    Assert.AreNotEqual(
                        property.GetValue(modified, null),
                        property.GetValue(deserialized, null),
                        "Property " + property.Name);
                }
            }
        }
Beispiel #7
0
        private static Serializer CreateSerializer()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(TagTests).Assembly);
            var serializer = new Serializer(settings);

            settings.AssemblyRegistry.UseShortTypeName = true;
            return(serializer);
        }
Beispiel #8
0
        public void DeserializeExplicitType()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(SerializationTests).Assembly);

            var    serializer = new Serializer();
            object result     = serializer.Deserialize(YamlFile("explicitType.yaml"), typeof(object));

            Assert.True(typeof(Z).IsAssignableFrom(result.GetType()));
            Assert.AreEqual("bbb", ((Z)result).aaa);
        }
Beispiel #9
0
        private void EnsureYamlSerializer()
        {
            lock (Lock)
            {
                if (serializer == null)
                {
                    // var clock = Stopwatch.StartNew();

                    var config = new SerializerSettings
                    {
                        EmitAlias = false,
                        LimitPrimitiveFlowSequence = 0,
                        Attributes                = new AttributeRegistry(),
                        PreferredIndent           = 4,
                        EmitShortTypeName         = true,
                        ComparerForKeySorting     = new DefaultMemberComparer(),
                        PreSerializer             = new ContextAttributeSerializer(),
                        PostSerializer            = new ErrorRecoverySerializer(),
                        SerializerFactorySelector = new ProfileSerializerFactorySelector(YamlSerializerFactoryAttribute.Default, "Assets"),
                        ChainedSerializerFactory  = x =>
                        {
                            var routingSerializer = x.FindNext <RoutingSerializer>();
                            if (routingSerializer == null)
                            {
                                throw new InvalidOperationException("RoutingSerializer expected in the chain of serializers");
                            }
                            // Prepend the IdentifiableObjectSerializer just before the routing serializer
                            routingSerializer.Prepend(new IdentifiableObjectSerializer());
                            // Prepend the ContextAttributeSerializer just before the routing serializer
                            routingSerializer.Prepend(new ContextAttributeSerializer());
                            // Prepend the ErrorRecoverySerializer at the beginning
                            routingSerializer.First.Prepend(new ErrorRecoverySerializer());
                        }
                    };

                    config.Attributes.PrepareMembersCallback += (objDesc, members) => PrepareMembersEvent?.Invoke(objDesc, members);

                    for (var index = RegisteredAssemblies.Count - 1; index >= 0; index--)
                    {
                        var registeredAssembly = RegisteredAssemblies[index];
                        config.RegisterAssembly(registeredAssembly);
                    }

                    var newSerializer = new Serializer(config);
                    newSerializer.Settings.ObjectSerializerBackend = new AssetObjectSerializerBackend(TypeDescriptorFactory.Default);

                    // Log.Info("New YAML serializer created in {0}ms", clock.ElapsedMilliseconds);
                    serializer = newSerializer;
                }
            }
        }
        public void TestSerializeSubClassWithOverriddenDefaultValues()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(SerializationSubClassTests).Assembly);
            var serializer = new Serializer(settings);

            var value    = new TestSubClass1();
            var text     = serializer.Serialize(value);
            var newValue = serializer.Deserialize <TestSubClass1>(text);

            Assert.Equal(value.IsSelected, newValue.IsSelected);
            Assert.Equal(value.Size.Width, newValue.Size.Width);
            Assert.Equal(value.Size.Height, newValue.Size.Height);
        }
Beispiel #11
0
        private Serializer CreateSerializer(ref Serializer localSerializer, bool generateIds)
        {
            // Early exit if already initialized
            if (localSerializer != null)
            {
                return(localSerializer);
            }

            lock (Lock)
            {
                if (localSerializer == null)
                {
                    // var clock = Stopwatch.StartNew();

                    var config = new SerializerSettings
                    {
                        EmitAlias = false,
                        LimitPrimitiveFlowSequence = 0,
                        Attributes                = new AttributeRegistry(),
                        PreferredIndent           = 4,
                        EmitShortTypeName         = true,
                        ComparerForKeySorting     = new DefaultMemberComparer(),
                        PreSerializer             = new ContextAttributeSerializer(),
                        PostSerializer            = new ErrorRecoverySerializer(),
                        SerializerFactorySelector = new ProfileSerializerFactorySelector(YamlSerializerFactoryAttribute.Default, "Assets")
                    };

                    if (generateIds)
                    {
                        config.Attributes.PrepareMembersCallback += PrepareMembersCallback;
                    }

                    for (int index = RegisteredAssemblies.Count - 1; index >= 0; index--)
                    {
                        var registeredAssembly = RegisteredAssemblies[index];
                        config.RegisterAssembly(registeredAssembly);
                    }

                    var newSerializer = new Serializer(config);
                    newSerializer.Settings.ObjectSerializerBackend = new AssetObjectSerializerBackend(TypeDescriptorFactory.Default);

                    // Log.Info("New YAML serializer created in {0}ms", clock.ElapsedMilliseconds);
                    localSerializer = newSerializer;
                }
            }

            return(localSerializer);
        }
Beispiel #12
0
        public Configuration Load(StreamReader streamReader)
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(ConfigurationSettings).Assembly);
            var serializer = new Serializer(settings);
            ConfigurationSettings configuration = serializer.Deserialize <ConfigurationSettings>(streamReader);

            if (!ValidateConfigurationSettings(configuration, out List <string> errors))
            {
                throw new FormatException($"Failed to load the configuration. Errors that occured:\n {String.Join("\n", errors)}");
            }

            return(new Configuration(configuration.Id, configuration.Ip, configuration.Port, configuration.UdpPort,
                                     configuration.LedCount, configuration.PwmPin, configuration.DmaChannel, configuration.Brightness));
        }
Beispiel #13
0
        public void DeserializeExplicitDictionary()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(SerializationTests).Assembly);

            var    serializer = new Serializer(settings);
            object result     = serializer.Deserialize(YamlFile("dictionaryExplicit.yaml"));

            Assert.True(typeof(IDictionary <string, int>).IsAssignableFrom(result.GetType()), "The deserialized object has the wrong type.");

            var dictionary = (IDictionary <string, int>)result;

            Assert.Equal(1, dictionary["key1"]);
            Assert.Equal(2, dictionary["key2"]);
        }
Beispiel #14
0
        public void TestImmutable()
        {
            var settings = new SerializerSettings();

            settings.RegisterTagMapping("MyClassImmutable", typeof(MyClassImmutable));

            // Automatically register MyClassImmutableSerializer assembly
            settings.RegisterAssembly(typeof(SerializationTests2).Assembly);

            var immutable  = new MyClassImmutable("Test", 1);
            var serializer = new Serializer(settings);
            var text       = serializer.Serialize(immutable);

            var newImmutable = serializer.Deserialize(text);

            Assert.AreEqual(immutable, newImmutable);
        }
Beispiel #15
0
        public void Enums()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(StringFormatFlags).Assembly);
            var serializer = new Serializer(settings);

            var flags = StringFormatFlags.NoClip | StringFormatFlags.NoFontFallback;

            var buffer = new StringWriter();

            serializer.Serialize(buffer, flags);

            var bufferAsText = buffer.ToString();
            var deserialized = (StringFormatFlags)serializer.Deserialize(bufferAsText, typeof(StringFormatFlags));

            Assert.AreEqual(flags, deserialized);
        }
Beispiel #16
0
        public YamlSerializer()
        {
            SerializerSettings settings = new SerializerSettings
            {
                EmitShortTypeName          = true,
                EmitDefaultValues          = false,
                LimitPrimitiveFlowSequence = 1
            };

            settings.RegisterAssembly(this.GetType().GetTypeInfo().Assembly);

            //settings.RegisterTagMapping("Entity", typeof(YamlEntity));
            //settings.RegisterTagMapping("ShaderLoadingSystem", typeof(ContentLoadingSystem<ShaderComponent>));
            //settings.RegisterTagMapping("ModelLoadingSystem", typeof(ContentLoadingSystem<ModelComponent>));
            //settings.RegisterTagMapping("TextureLoadingSystem", typeof(ContentLoadingSystem<ContentComponent>));
            //settings.RegisterTagMapping("TextureCubeLoadingSystem", typeof(ContentLoadingSystem<TextureCubeComponent>));
            serializer = new Serializer(settings);
        }
        public void NestedDocumentShouldDeserializeProperly()
        {
            var serializer = new Serializer(new SerializerSettings()
            {
                EmitDefaultValues = true
            });

            // serialize AMessage
            var tw = new StringWriter();

            serializer.Serialize(tw, new AMessage {
                Payload = new PayloadA {
                    X = 5, Y = 6
                }
            });
            Dump.WriteLine(tw);

            // stick serialized AMessage in envelope and serialize it
            var e = new Env {
                Type = "some-type", Payload = tw.ToString()
            };

            tw = new StringWriter();
            serializer.Serialize(tw, e);
            Dump.WriteLine(tw);

            Dump.WriteLine("${0}$", e.Payload);

            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(Env).Assembly);
            var deserializer = new Serializer(settings);
            // deserialize envelope
            var e2 = deserializer.Deserialize <Env>(new StringReader(tw.ToString()));

            Dump.WriteLine("${0}$", e2.Payload);

            // deserialize payload - fails if EmitDefaults is set
            var message = deserializer.Deserialize <AMessage>(e2.Payload);

            Assert.NotNull(message.Payload);
            Assert.AreEqual(message.Payload.X, 5);
            Assert.AreEqual(message.Payload.Y, 6);
        }
Beispiel #18
0
        public void RoundtripWithTypeConverter()
        {
            var buffer   = new StringWriter();
            var x        = new SomeCustomType("Yo");
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(SerializationTests).Assembly);
            settings.SerializerFactorySelector.TryAddFactory(new CustomTypeConverter());
            var serializer = new Serializer(settings);

            serializer.Serialize(buffer, x);

            Dump.WriteLine(buffer);

            var bufferText = buffer.ToString();
            var copy       = serializer.Deserialize <SomeCustomType>(bufferText);

            Assert.Equal("Yo", copy.Value);
        }
        public void TestSerializeSubClassWithValuesSameAsBaseClassValues()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(SerializationSubClassTests).Assembly);
            var serializer = new Serializer(settings);

            var value = new TestSubClass1();

            value.IsSelected = false;
            value.Size       = new Size {
                Width = 10, Height = 10
            };
            var text     = serializer.Serialize(value);
            var newValue = serializer.Deserialize <TestSubClass1>(text);

            Assert.Equal(value.IsSelected, newValue.IsSelected);
            Assert.Equal(value.Size.Width, newValue.Size.Width);
            Assert.Equal(value.Size.Height, newValue.Size.Height);
        }
Beispiel #20
0
        public void SerializationDoesNotIncludeDefaultValueWhenNotAsked()
        {
            var settings = new SerializerSettings()
            {
                EmitDefaultValues = false
            };

            settings.RegisterAssembly(typeof(X).Assembly);
            var serializer = new Serializer(settings);

            var buffer   = new StringWriter();
            var original = new X();

            serializer.Serialize(buffer, original, typeof(X));

            Dump.WriteLine(buffer);
            var bufferText = buffer.ToString();

            Assert.False(bufferText.Contains("MyString"));
        }
Beispiel #21
0
        public void DeserializeEnumerable()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(SerializationTests).Assembly);

            var serializer = new Serializer(settings);
            var buffer     = new StringWriter();
            var z          = new[] { new Z {
                                         aaa = "Yo"
                                     } };

            serializer.Serialize(buffer, z);

            var bufferAsText = buffer.ToString();
            var result       = (IEnumerable <Z>)serializer.Deserialize(bufferAsText, typeof(IEnumerable <Z>));

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("Yo", result.First().aaa);
        }
Beispiel #22
0
        private Serializer CreateSerializer(ref Serializer localSerializer)
        {
            // Early exit if already initialized
            if (localSerializer != null)
            {
                return(localSerializer);
            }

            lock (Lock)
            {
                if (localSerializer == null)
                {
                    // var clock = Stopwatch.StartNew();

                    var config = new SerializerSettings
                    {
                        EmitAlias = false,
                        LimitPrimitiveFlowSequence = 0,
                        Attributes                = new AttributeRegistry(),
                        PreferredIndent           = 4,
                        EmitShortTypeName         = true,
                        ComparerForKeySorting     = new DefaultMemberComparer(),
                        SerializerFactorySelector = CreateSelector(),
                    };

                    for (int index = RegisteredAssemblies.Count - 1; index >= 0; index--)
                    {
                        var registeredAssembly = RegisteredAssemblies[index];
                        config.RegisterAssembly(registeredAssembly);
                    }

                    var newSerializer = new Serializer(config);
                    newSerializer.Settings.ObjectSerializerBackend = new DefaultObjectSerializerBackend();

                    // Log.Info("New YAML serializer created in {0}ms", clock.ElapsedMilliseconds);
                    localSerializer = newSerializer;
                }
            }

            return(localSerializer);
        }
Beispiel #23
0
        public void DeserializeNullList()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(Z).Assembly);
            var          sut    = new Serializer(settings);
            const string yaml   = @"!Xenko.Core.Yaml.Tests.Serialization.SerializationTests+W
    MyList:
        - aaa
        - bbb
        - ccc
";
            var          result = (W)sut.Deserialize(yaml, typeof(W));

            Assert.NotNull(result);
            Assert.NotNull(result.MyList);
            Assert.Equal(3, result.MyList.Count);
            Assert.Equal("aaa", result.MyList[0]);
            Assert.Equal("bbb", result.MyList[1]);
            Assert.Equal("ccc", result.MyList[2]);
        }
Beispiel #24
0
        public void SerializationOfNullWorksInJson()
        {
            var settings = new SerializerSettings()
            {
                EmitDefaultValues = true, EmitJsonComptible = true
            };

            settings.RegisterAssembly(typeof(X).Assembly);
            var serializer = new Serializer(settings);

            var buffer   = new StringWriter();
            var original = new X {
                MyString = null
            };

            serializer.Serialize(buffer, original, typeof(X));

            Dump.WriteLine(buffer);
            var bufferText = buffer.ToString();

            Assert.True(bufferText.Contains("MyString"));
        }
Beispiel #25
0
        private static Serializer CreateSerializer(bool keepOnlySealedOverrides, ref Serializer localSerializer)
        {
            if (localSerializer == null)
            {
                var config = new SerializerSettings()
                {
                    EmitAlias = false,
                    LimitPrimitiveFlowSequence = 0,
                    Attributes      = new AtributeRegistryFilter(),
                    PreferredIndent = 4,
                };

                foreach (var registeredAssembly in RegisteredAssemblies)
                {
                    config.RegisterAssembly(registeredAssembly);
                }

                localSerializer = new Serializer(config);
                localSerializer.Settings.ObjectSerializerBackend = new OverrideKeyMappingTransform(TypeDescriptorFactory.Default, keepOnlySealedOverrides);
            }

            return(localSerializer);
        }
Beispiel #26
0
        public void SerializationRespectsYamlIgnoreAttribute()
        {
            var settings = new SerializerSettings();

            settings.RegisterAssembly(typeof(ContainsIgnore).Assembly);
            var serializer = new Serializer(settings);

            var buffer = new StringWriter();
            var orig   = new ContainsIgnore();

            serializer.Serialize(buffer, orig);

            Dump.WriteLine(buffer);

            var copy = (ContainsIgnore)serializer.Deserialize(new StringReader(buffer.ToString()), typeof(ContainsIgnore));

            Assert.Throws <NotImplementedException>(() =>
            {
                if (copy.IgnoreMe == null)
                {
                }
            });
        }
Beispiel #27
0
        private static void RegisterDefaults(SerializerSettings settings)
        {
            settings.EmitAlias = false;

            var attributes = (AttributeRegistry)settings.Attributes;

            settings.RegisterTagMapping("!Vector2", typeof(Vector2));
            attributes.Register(GetTypeInfo <Vector2>(), new YamlStyleAttribute(YamlStyle.Flow));
            attributes.Register(GetField <Vector2>("X"), new YamlMemberAttribute(0));
            attributes.Register(GetField <Vector2>("Y"), new YamlMemberAttribute(1));

            settings.RegisterTagMapping("!Vector3", typeof(Vector3));
            attributes.Register(GetTypeInfo <Vector3>(), new YamlStyleAttribute(YamlStyle.Flow));
            attributes.Register(GetField <Vector3>("X"), new YamlMemberAttribute(0));
            attributes.Register(GetField <Vector3>("Y"), new YamlMemberAttribute(1));
            attributes.Register(GetField <Vector3>("Z"), new YamlMemberAttribute(2));

            settings.RegisterTagMapping("!Vector4", typeof(Vector4));
            attributes.Register(GetTypeInfo <Vector4>(), new YamlStyleAttribute(YamlStyle.Flow));
            attributes.Register(GetField <Vector4>("X"), new YamlMemberAttribute(0));
            attributes.Register(GetField <Vector4>("Y"), new YamlMemberAttribute(1));
            attributes.Register(GetField <Vector4>("Z"), new YamlMemberAttribute(2));
            attributes.Register(GetField <Vector4>("W"), new YamlMemberAttribute(3));

            settings.RegisterTagMapping("!Color", typeof(Color));
            attributes.Register(GetTypeInfo <Color>(), new YamlStyleAttribute(YamlStyle.Flow));
            attributes.Register(GetField <Color>("R"), new YamlMemberAttribute(0));
            attributes.Register(GetField <Color>("G"), new YamlMemberAttribute(1));
            attributes.Register(GetField <Color>("B"), new YamlMemberAttribute(2));
            attributes.Register(GetField <Color>("A"), new YamlMemberAttribute(3));

            settings.RegisterTagMapping("!ColorBGRA", typeof(ColorBGRA));
            attributes.Register(GetTypeInfo <ColorBGRA>(), new YamlStyleAttribute(YamlStyle.Flow));
            attributes.Register(GetField <ColorBGRA>("B"), new YamlMemberAttribute(0));
            attributes.Register(GetField <ColorBGRA>("G"), new YamlMemberAttribute(1));
            attributes.Register(GetField <ColorBGRA>("R"), new YamlMemberAttribute(2));
            attributes.Register(GetField <ColorBGRA>("A"), new YamlMemberAttribute(3));

            settings.RegisterTagMapping("!Color3", typeof(Color3));
            attributes.Register(GetTypeInfo <Color3>(), new YamlStyleAttribute(YamlStyle.Flow));
            attributes.Register(GetField <Color3>("Red"), new YamlMemberAttribute("R")
            {
                Order = 0
            });
            attributes.Register(GetField <Color3>("Green"), new YamlMemberAttribute("G")
            {
                Order = 1
            });
            attributes.Register(GetField <Color3>("Blue"), new YamlMemberAttribute("B")
            {
                Order = 2
            });

            settings.RegisterTagMapping("!Color4", typeof(Color4));
            attributes.Register(GetTypeInfo <Color4>(), new YamlStyleAttribute(YamlStyle.Flow));
            attributes.Register(GetField <Color4>("Red"), new YamlMemberAttribute("R")
            {
                Order = 0
            });
            attributes.Register(GetField <Color4>("Green"), new YamlMemberAttribute("G")
            {
                Order = 1
            });
            attributes.Register(GetField <Color4>("Blue"), new YamlMemberAttribute("B")
            {
                Order = 2
            });
            attributes.Register(GetField <Color4>("Alpha"), new YamlMemberAttribute("A")
            {
                Order = 3
            });

            settings.RegisterAssembly(GetAssembly <Vector2>());
        }