Exemple #1
0
        public static string ToYaml(string Name, SceneAnim sceneAnim)
        {
            var serializerSettings = new SerializerSettings()
            {
                //  EmitTags = false
            };

            serializerSettings.DefaultStyle          = YamlStyle.Any;
            serializerSettings.ComparerForKeySorting = null;
            serializerSettings.RegisterTagMapping("AnimConfig", typeof(AnimConfig));

            var config = new AnimConfig();

            config.ToYaml(sceneAnim);

            var    serializer = new Serializer(serializerSettings);
            string yaml       = serializer.Serialize(config, typeof(AnimConfig));

            return(yaml);
        }
Exemple #2
0
        public static string ToYaml(string Name, MaterialAnim MatAnim, FMAA.AnimationType animType)
        {
            var serializerSettings = new SerializerSettings()
            {
                EmitTags            = false,
                EmitAlias           = false,
                EmitCapacityForList = false,
                EmitShortTypeName   = false
            };

            serializerSettings.DefaultStyle          = YamlStyle.Any;
            serializerSettings.ComparerForKeySorting = null;
            serializerSettings.RegisterTagMapping("AnimConfig", typeof(AnimConfig));

            var config = new AnimConfig();

            config.ToYaml(MatAnim, animType);

            var    serializer = new Serializer(serializerSettings);
            string yaml       = serializer.Serialize(config, typeof(AnimConfig));

            return(yaml);
        }
        public void TestKeyTransform()
        {
            var specialTransform = new MyMappingKeyTransform();
            var settings         = new SerializerSettings()
            {
                LimitPrimitiveFlowSequence = 4
            };

            settings.ObjectSerializerBackend = specialTransform;
            settings.RegisterTagMapping("ClassWithKeyTransform", typeof(ClassWithKeyTransform));

            var myCustomObject = new ClassWithKeyTransform();

            myCustomObject.Name = "Yes";
            myCustomObject.KeyValues.Add("Test1", 1);
            myCustomObject.KeyValues.Add("Test2", 2);
            myCustomObject.KeyValues.Add("KeyNotModified1", 1);
            myCustomObject.KeyValues.Add("KeyNotModified2", 2);

            var serializer         = new Serializer(settings);
            var myCustomObjectText = serializer.Serialize(myCustomObject);

            var myCustomObject2 = (ClassWithKeyTransform)serializer.Deserialize(myCustomObjectText);

            Assert.AreEqual(3, specialTransform.SpecialKeys.Count);

            Assert.AreEqual(myCustomObject2.KeyValues, specialTransform.SpecialKeys[1].Item1);
            Assert.AreEqual(myCustomObject2.KeyValues, specialTransform.SpecialKeys[2].Item1);

            Assert.AreEqual("Test1", specialTransform.SpecialKeys[1].Item2);
            Assert.AreEqual("Test2", specialTransform.SpecialKeys[2].Item2);

            Assert.AreEqual(myCustomObject2, specialTransform.SpecialKeys[0].Item1);
            Assert.IsInstanceOf <IMemberDescriptor>(specialTransform.SpecialKeys[0].Item2);

            Assert.AreEqual("Name", ((IMemberDescriptor)specialTransform.SpecialKeys[0].Item2).Name);
        }
        public void TestMyCustomClassWithSpecialMembers()
        {
            var text = @"!MyCustomClassWithSpecialMembers
BasicList:
  - 1
  - 2
BasicMap:
  a: 1
  b: 2
ListByContent:
  - a
  - b
Name: Yes
StringList:
  - 1
  - 2
StringListByContent:
  - 3
  - 4
StringMap:
  c: yes
  d: 3
StringMapbyContent:
  e: 4
  f: no
Value: 0
".Trim();

            var settings = new SerializerSettings()
            {
                LimitPrimitiveFlowSequence = 0
            };

            settings.RegisterTagMapping("MyCustomClassWithSpecialMembers", typeof(MyCustomClassWithSpecialMembers));
            SerialRoundTrip(settings, text);
        }
Exemple #5
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>());
        }
Exemple #6
0
 public AssetObjectSerializerBackend(SerializerSettings settings, IContentManager contentManager)
 {
     settings.RegisterTagMapping("!asset", typeof(AssetName));
     settings.RegisterSerializerFactory(new AssetNameFactory());
     this.contentManager = contentManager;
 }
        public void TestStyles()
        {
            var settings = new SerializerSettings()
            {
                LimitPrimitiveFlowSequence = 4
            };

            settings.RegisterTagMapping("ClassNoStyle", typeof(ClassNoStyle));
            settings.RegisterTagMapping("ClassWithStyle", typeof(ClassWithStyle));
            settings.ObjectSerializerBackend = new FormatListObject();

            var classNoStyle = new ClassNoStyle();

            classNoStyle.A_ListWithCustomStyle.Add("a");
            classNoStyle.A_ListWithCustomStyle.Add("b");
            classNoStyle.A_ListWithCustomStyle.Add("c");
            classNoStyle.B_ClassWithStyle = new ClassWithStyle()
            {
                Name = "name1", Value = 1
            };
            classNoStyle.C_ClassWithStyleOverridenByLocalYamlStyle = new ClassWithStyle()
            {
                Name = "name2", Value = 2
            };
            classNoStyle.D_ListHandleByDynamicStyleFormat.Add(1);
            classNoStyle.D_ListHandleByDynamicStyleFormat.Add(2);
            classNoStyle.D_ListHandleByDynamicStyleFormat.Add(3);
            classNoStyle.E_ListDefaultPrimitiveLimit.Add(1);
            classNoStyle.E_ListDefaultPrimitiveLimit.Add(2);
            classNoStyle.E_ListDefaultPrimitiveLimitExceed.Add(1);
            classNoStyle.E_ListDefaultPrimitiveLimitExceed.Add(2);
            classNoStyle.E_ListDefaultPrimitiveLimitExceed.Add(3);
            classNoStyle.E_ListDefaultPrimitiveLimitExceed.Add(4);
            classNoStyle.E_ListDefaultPrimitiveLimitExceed.Add(5);
            classNoStyle.F_ListClassWithStyleDefaultFormat.Add(new ClassWithStyle()
            {
                Name = "name3", Value = 3
            });
            classNoStyle.G_ListCustom.Name = "name4";
            classNoStyle.G_ListCustom.Add(1);
            classNoStyle.G_ListCustom.Add(2);
            classNoStyle.G_ListCustom.Add(3);
            classNoStyle.G_ListCustom.Add(4);
            classNoStyle.G_ListCustom.Add(5);
            classNoStyle.G_ListCustom.Add(6);
            classNoStyle.G_ListCustom.Add(7);

            var serializer = new Serializer(settings);
            var text       = serializer.Serialize(classNoStyle).Trim();

            var textReference = @"!ClassNoStyle
A_ListWithCustomStyle: [a, b, c]
B_ClassWithStyle: {Name: name1, Value: 1}
C_ClassWithStyleOverridenByLocalYamlStyle:
  Name: name2
  Value: 2
D_ListHandleByDynamicStyleFormat: [1, 2, 3]
E_ListDefaultPrimitiveLimit: [1, 2]
E_ListDefaultPrimitiveLimitExceed:
  - 1
  - 2
  - 3
  - 4
  - 5
F_ListClassWithStyleDefaultFormat:
  - {Name: name3, Value: 3}
G_ListCustom: {Name: name4, ~Items: [1, 2, 3, 4, 5, 6, 7]}";

            Assert.AreEqual(textReference, text);
        }