Example #1
0
        public void PersistableDictionary_ShouldSerializeValue()
        {
            var dictionary = new PersistableDictionary <string, double>
            {
                { "a", -12.4 },
                { "b", 6.01 },
            };

            Assert.That(dictionary.Value, Is.EqualTo("{\"a\":-12.4,\"b\":6.01}"));
        }
Example #2
0
        public void PersistableDictionary_ShouldDeserializeEmptyValue()
        {
            var dictionary = new PersistableDictionary <string, double> {
                { "x", 0 }
            };

            dictionary.Value = "";

            Assert.That(dictionary.Count, Is.EqualTo(0));
        }
Example #3
0
        public void PersistableDictionary_ShouldDeserializeValue()
        {
            var dictionary = new PersistableDictionary <string, string> {
                { "x", "y" }
            };

            dictionary.Value = "{\"a\":\"A\",\"b\":\"B\"}";

            Assert.That(dictionary.Count, Is.EqualTo(2));
            Assert.That(dictionary["a"], Is.EqualTo("A"));
            Assert.That(dictionary["b"], Is.EqualTo("B"));
        }
Example #4
0
        internal static PersistableDictionary GetDictionaryProperty(IAnchorStoreObject item, PropertyDefinition propertyDefinition, bool required)
        {
            AnchorUtil.ThrowOnNullArgument(item, "item");
            AnchorUtil.ThrowOnNullArgument(propertyDefinition, "propertyDefinition");
            string property = AnchorHelper.GetProperty <string>(item, propertyDefinition, required);

            if (property == null)
            {
                return(null);
            }
            PersistableDictionary result;

            try
            {
                result = PersistableDictionary.Create(property);
            }
            catch (XmlException innerException)
            {
                throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, property), innerException);
            }
            return(result);
        }
Example #5
0
 internal static void SetDictionaryProperty(IPropertyBag item, PropertyDefinition propertyDefinition, PersistableDictionary persistDictionary)
 {
     AnchorUtil.ThrowOnNullArgument(item, "item");
     AnchorUtil.ThrowOnNullArgument(propertyDefinition, "propertyDefinition");
     AnchorUtil.ThrowOnNullArgument(persistDictionary, "persistDictionary");
     item[propertyDefinition] = persistDictionary.Serialize();
 }