public DataNode Write(ISerializationManager serializationManager, Rsi value, bool alwaysWrite = false, ISerializationContext?context = null) { var mapping = new MappingDataNode(); mapping.Add("sprite", serializationManager.WriteValue(value.RsiPath)); mapping.Add("state", new ValueDataNode(value.RsiState)); return(mapping); }
public DataNode BaselineWriteSeedDataDefinition() { var mapping = new MappingDataNode(); mapping.Add("id", Seed.ID); mapping.Add("name", Seed.Name); mapping.Add("seedName", Seed.SeedName); mapping.Add("displayName", Seed.DisplayName); mapping.Add("productPrototypes", Seed.ProductPrototypes); mapping.Add("harvestRepeat", Seed.HarvestRepeat.ToString()); mapping.Add("lifespan", Seed.Lifespan.ToString(CultureInfo.InvariantCulture)); mapping.Add("maturation", Seed.Maturation.ToString(CultureInfo.InvariantCulture)); mapping.Add("production", Seed.Production.ToString(CultureInfo.InvariantCulture)); mapping.Add("yield", Seed.Yield.ToString(CultureInfo.InvariantCulture)); mapping.Add("potency", Seed.Potency.ToString(CultureInfo.InvariantCulture)); mapping.Add("growthStages", Seed.GrowthStages.ToString(CultureInfo.InvariantCulture)); mapping.Add("idealLight", Seed.IdealLight.ToString(CultureInfo.InvariantCulture)); mapping.Add("idealHeat", Seed.IdealHeat.ToString(CultureInfo.InvariantCulture)); var chemicals = new MappingDataNode(); foreach (var(name, quantity) in Seed.Chemicals) { chemicals.Add(name, new MappingDataNode { ["Min"] = new ValueDataNode(quantity.Min.ToString(CultureInfo.InvariantCulture)), ["Max"] = new ValueDataNode(quantity.Max.ToString(CultureInfo.InvariantCulture)), ["PotencyDivisor"] = new ValueDataNode(quantity.PotencyDivisor.ToString(CultureInfo.InvariantCulture)) }); } mapping.Add("chemicals", chemicals); return(mapping); }
public void DeserializationTest() { var dictionary = new Dictionary <int, string> { [1] = "A", [2] = "B", [3] = "C" }; var node = new MappingDataNode(); node.Add("1", new ValueDataNode("A")); node.Add("2", new ValueDataNode("B")); node.Add("3", new ValueDataNode("C")); var deserializedDictionary = Serialization.ReadValue <Dictionary <int, string> >(node); Assert.That(deserializedDictionary, Is.EqualTo(dictionary)); }
public SerializationReadBenchmark() { InitializeSerialization(); StringDataDefNode = new MappingDataNode(); StringDataDefNode.Add(new ValueDataNode("string"), new ValueDataNode("ABC")); var yamlStream = new YamlStream(); yamlStream.Load(new StringReader(SeedDataDefinition.Prototype)); SeedNode = yamlStream.Documents[0].RootNode.ToDataNodeCast <SequenceDataNode>().Cast <MappingDataNode>(0); }
public void SerializeListTest() { // Arrange var data = _serializableList; var serMan = IoCManager.Resolve <ISerializationManager>(); var sequence = (SequenceDataNode)serMan.WriteValue(data); var mapping = new MappingDataNode(); mapping.Add("datalist", sequence); // Assert var result = NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(_serializedListYaml)); }
private MappingDataNode InterfaceWrite( ISerializationManager serializationManager, IDictionary <TKey, TValue> value, bool alwaysWrite = false, ISerializationContext?context = null) { var mappingNode = new MappingDataNode(); foreach (var(key, val) in value) { mappingNode.Add( serializationManager.WriteValue(key, alwaysWrite, context), serializationManager.WriteValue(typeof(TValue), val, alwaysWrite, context)); } return(mappingNode); }
public MappingDataNode Attributes() { var node = new MappingDataNode(); while (TryGetAttribute(out var key, out var value)) { if (value == "none") { continue; } if (value[0] == '"') { value = value.Substring(1, value.Length - 2); } node.Add(key, value); } return(node); }
public void ParityTest() { var mapping = new MappingDataNode(); mapping.Add(GetOnlyPropertyName, new ValueDataNode("5")); mapping.Add(GetOnlyPropertyFieldTargetedName, new ValueDataNode("10")); mapping.Add(GetAndSetPropertyName, new ValueDataNode("15")); mapping.Add(FieldName, new ValueDataNode("20")); mapping.Add(GetOnlyPropertyWithOtherAttributeFieldTargetedName, new ValueDataNode("25")); mapping.Add(GetOnlyPropertyFieldTargetedAndOtherAttributeName, new ValueDataNode("30")); var definition = Serialization.ReadValue <PropertyAndFieldDefinitionTestDefinition>(mapping); Assert.NotNull(definition); // Get only property with backing field, property targeted Assert.That(definition !.GetOnlyProperty, Is.EqualTo(5)); var backingField = definition.GetType().GetBackingField(GetOnlyPropertyName); Assert.NotNull(backingField); var backingFieldValue = backingField !.GetValue(definition); Assert.That(backingFieldValue, Is.EqualTo(5)); // Get only property with backing field, field targeted Assert.That(definition.GetOnlyPropertyFieldTargeted, Is.EqualTo(10)); // Get and set property with backing field, property targeted Assert.That(definition.GetAndSetProperty, Is.EqualTo(15)); // Field Assert.That(definition.Field, Is.EqualTo(20)); // Get only property with backing field, property targeted with another attribute field targeted Assert.That(definition.GetOnlyPropertyWithOtherAttributeFieldTargeted, Is.EqualTo(25)); var property = definition.GetType().GetProperty(GetOnlyPropertyWithOtherAttributeFieldTargetedName); Assert.NotNull(property); var propertyInfo = new SpecificPropertyInfo(property !); Assert.NotNull(propertyInfo.GetAttribute <DataFieldAttribute>()); Assert.NotNull(propertyInfo.GetBackingField() !.GetAttribute <AlwaysPushInheritanceAttribute>()); // We check for the property info properly finding field targeted attributes as // well, otherwise we run the risk of the data field being targeted to the // property but an additional attribute like AlwaysPushInheritance being targeted // to the field, as was the case in EntityPrototype. // And I don't want to debug that ever again. Assert.NotNull(propertyInfo.DeclaringType); var dataDefinition = ((SerializationManager)Serialization).GetDefinition(propertyInfo.DeclaringType !); Assert.NotNull(dataDefinition); var alwaysPushDataField = propertyInfo.GetAttribute <DataFieldAttribute>(); var propertyDefinition = dataDefinition !.BaseFieldDefinitions.Single(e => e.Attribute.Equals(alwaysPushDataField)); var inheritanceBehaviour = propertyDefinition.InheritanceBehavior; Assert.That(inheritanceBehaviour, Is.EqualTo(InheritanceBehavior.Always)); // Get only property with backing field, field targeted with another attribute property targeted Assert.That(definition.GetOnlyPropertyFieldTargetedAndOtherAttribute, Is.EqualTo(30)); property = definition.GetType().GetProperty(GetOnlyPropertyFieldTargetedAndOtherAttributeName); Assert.NotNull(property); propertyInfo = new SpecificPropertyInfo(property !); // Data field is targeted to the backing field Assert.NotNull(propertyInfo.GetBackingField() !.GetAttribute <DataFieldAttribute>()); Assert.Null(propertyInfo.GetAttribute <DataFieldAttribute>()); Assert.NotNull(propertyInfo.GetAttribute <DataFieldAttribute>(true)); // NeverPushInheritanceAttribute is targeted to the property Assert.NotNull(propertyInfo.GetAttribute <NeverPushInheritanceAttribute>()); Assert.Null(propertyInfo.GetBackingField() !.GetAttribute <NeverPushInheritanceAttribute>()); Assert.NotNull(propertyInfo.GetAttribute <NeverPushInheritanceAttribute>(true)); var neverPushDataField = propertyInfo.GetBackingField() !.GetAttribute <DataFieldAttribute>(); propertyDefinition = dataDefinition !.BaseFieldDefinitions.Single(e => e.Attribute.Equals(neverPushDataField)); inheritanceBehaviour = propertyDefinition.InheritanceBehavior; dataDefinition = ((SerializationManager)Serialization).GetDefinition(property !.DeclaringType !); Assert.NotNull(dataDefinition); Assert.That(inheritanceBehaviour, Is.EqualTo(InheritanceBehavior.Never)); }