Ejemplo n.º 1
0
        public void TestSetProperties()
        {
            var obj = JsonConverter.ToMap(
                "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 }, \"value3\": [ 444, { \"value311\": 555 } ] }"
                );

            var values = new Dictionary <string, object> {
                //{ "", null },
                { "value1", "AAA" },
                { "value2", "BBB" },
                { "value3.1.value312", "CCC" },
                { "value3.3", "DDD" },
                { "value4.1", "EEE" }
            };

            RecursiveObjectWriter.SetProperties(obj, values);

            var resultValues = RecursiveObjectReader.GetProperties(obj);

            Assert.Equal(9, resultValues.Count);
            Assert.Equal("AAA", resultValues["value1"]);
            Assert.Equal("BBB", resultValues["value2"]);
            Assert.False(resultValues.ContainsKey("value2.value21"));
            Assert.Equal(444, (int)(long)resultValues["value3.0"]);
            Assert.Equal(555, (int)(long)resultValues["value3.1.value311"]);
            Assert.Equal("CCC", resultValues["value3.1.value312"]);
            Assert.Null(resultValues["value3.2"]);
            Assert.Equal("DDD", resultValues["value3.3"]);
            Assert.Null(resultValues["value4.0"]);
            Assert.Equal("EEE", resultValues["value4.1"]);
        }
Ejemplo n.º 2
0
        public void TestSetProperty()
        {
            var obj = JsonConverter.ToMap(
                "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 }, \"value3\": [ 444, { \"value311\": 555 } ] }"
                );

            //RecursiveObjectWriter.SetProperty(obj, "", null);
            RecursiveObjectWriter.SetProperty(obj, "value1", "AAA");
            RecursiveObjectWriter.SetProperty(obj, "value2", "BBB");
            RecursiveObjectWriter.SetProperty(obj, "value3.1.value312", "CCC");
            RecursiveObjectWriter.SetProperty(obj, "value3.3", "DDD");
            RecursiveObjectWriter.SetProperty(obj, "value4.1", "EEE");

            var values = RecursiveObjectReader.GetProperties(obj);

            Assert.Equal(9, values.Count);
            Assert.Equal("AAA", values["value1"]);
            Assert.Equal("BBB", values["value2"]);
            Assert.False(values.ContainsKey("value2.value21"));
            Assert.Equal(444, (int)(long)values["value3.0"]);
            Assert.Equal(555, (int)(long)values["value3.1.value311"]);
            Assert.Equal("CCC", values["value3.1.value312"]);
            Assert.Null(values["value3.2"]);
            Assert.Equal("DDD", values["value3.3"]);
            Assert.Null(values["value4.0"]);
            Assert.Equal("EEE", values["value4.1"]);
        }
        public void TestSetProperties()
        {
            var obj = JsonConverter.ToMap(
                "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 }, \"value3\": [ 444, { \"value311\": 555 } ] }"
                );

            var values = Parameters.FromTuples(
                //"", null,
                "value1", "AAA",
                "value2", "BBB",
                "value3.1.value312", "CCC",
                "value3.3", "DDD",
                "value4.1", "EEE"
                );

            RecursiveObjectWriter.SetProperties(obj, values);

            var resultValues = RecursiveObjectReader.GetProperties(obj);

            Assert.Equal(8, resultValues.Count);
            Assert.Equal("AAA", resultValues["value1"]);
            Assert.Equal("BBB", resultValues["value2"]);
            Assert.False(resultValues.ContainsKey("value2.value21"));
            Assert.Equal(444, (int)(long)resultValues["value3.0"]);
            Assert.Equal(555, (int)(long)resultValues["value3.1.value311"]);
            Assert.Equal("CCC", resultValues["value3.1.value312"]);
            Assert.Null(resultValues["value3.2"]);
            Assert.Equal("DDD", resultValues["value3.3"]);
            Assert.Equal("EEE", resultValues["value4.1"]);
        }
Ejemplo n.º 4
0
 public void AssignTo(object value)
 {
     if (value == null || this.Count == 0)
     {
         return;
     }
     RecursiveObjectWriter.CopyProperties(value, (object)this);
 }
Ejemplo n.º 5
0
 public override void Set(string path, object value)
 {
     if (string.IsNullOrWhiteSpace(path))
     {
         return;
     }
     if (path.IndexOf(".", StringComparison.Ordinal) > 0)
     {
         RecursiveObjectWriter.SetProperty((object)this, path, value);
     }
     else
     {
         base.Set(path, value);
     }
 }
Ejemplo n.º 6
0
        public RestOperationParameters Override(RestOperationParameters parameters, bool recursive)
        {
            RestOperationParameters parameters1 = new RestOperationParameters();

            if (recursive)
            {
                RecursiveObjectWriter.CopyProperties((object)parameters1, (object)this);
                RecursiveObjectWriter.CopyProperties((object)parameters1, (object)parameters);
            }
            else
            {
                ObjectWriter.SetProperties((object)parameters1, (IDictionary <string, object>) this);
                ObjectWriter.SetProperties((object)parameters1, (IDictionary <string, object>)parameters);
            }
            return(parameters1);
        }
Ejemplo n.º 7
0
        public RestOperationParameters SetDefaults(RestOperationParameters defaultParameters, bool recursive)
        {
            RestOperationParameters parameters = new RestOperationParameters();

            if (recursive)
            {
                RecursiveObjectWriter.CopyProperties((object)parameters, (object)defaultParameters);
                RecursiveObjectWriter.CopyProperties((object)parameters, (object)this);
            }
            else
            {
                ObjectWriter.SetProperties((object)parameters, (IDictionary <string, object>)defaultParameters);
                ObjectWriter.SetProperties((object)parameters, (IDictionary <string, object>) this);
            }
            return(parameters);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Set default values from specified Parameters and returns a new Parameters object.
        /// </summary>
        /// <param name="defaultParameters">Parameters with default parameter values.</param>
        /// <param name="recursive">(optional) true to perform deep copy, and false for shallow copy.Default: false</param>
        /// <returns>a new Parameters object.</returns>
        public Parameters SetDefaults(Parameters defaultParameters, bool recursive)
        {
            var result = new Parameters();

            if (recursive)
            {
                RecursiveObjectWriter.CopyProperties(result, defaultParameters);
                RecursiveObjectWriter.CopyProperties(result, this);
            }
            else
            {
                ObjectWriter.SetProperties(result, defaultParameters);
                ObjectWriter.SetProperties(result, this);
            }

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Overrides parameters with new values from specified Parameters and returns a
        /// new Parameters object.
        /// </summary>
        /// <param name="parameters">Parameters with parameters to override the current values.</param>
        /// <param name="recursive">(optional) true to perform deep copy, and false for shallow copy.Default: false</param>
        /// <returns>a new Parameters object.</returns>
        public Parameters Override(Parameters parameters, bool recursive)
        {
            var result = new Parameters();

            if (recursive)
            {
                RecursiveObjectWriter.CopyProperties(result, this);
                RecursiveObjectWriter.CopyProperties(result, parameters);
            }
            else
            {
                ObjectWriter.SetProperties(result, this);
                ObjectWriter.SetProperties(result, parameters);
            }

            return(result);
        }