예제 #1
0
        public void PropertyBag_GetPropertiesTyped()
        {
            var propertyBag = PropertyBag.GetPropertyBag <ClassWithPrimitives>();
            var container   = new ClassWithPrimitives();

            Measure.Method(() => {
                if (propertyBag is ContainerPropertyBag <ClassWithPrimitives> typed)
                {
                    /*
                     * foreach (var property in typed.m_PropertiesList)
                     * {
                     * }
                     */
                }
                else
                {
                    foreach (var property in propertyBag.GetProperties(ref container))
                    {
                    }
                }
            })
            .WarmupCount(1)
            .MeasurementCount(100)
            .IterationsPerMeasurement(100)
            .GC()
            .Run();
        }
        public void ManagedObjectClone_ClassWithPrimitives()
        {
            var src = new ClassWithPrimitives {
                A = 1, B = 2.3f, C = true, D = null
            };
            var dst = new ManagedObjectClone().Clone(src) as ClassWithPrimitives;

            Assert.That(dst, Is.Not.Null);
            Assert.That(dst, Is.Not.SameAs(src));
            Assert.That(dst.A, Is.EqualTo(src.A));
            Assert.That(dst.B, Is.EqualTo(src.B));
            Assert.That(dst.C, Is.EqualTo(src.C));
            Assert.That(dst.D, Is.EqualTo(src.D));
        }
예제 #3
0
        public static void ClassWithPrimitivesObjectConverter()
        {
            string expected = @"{
""MyIntProperty"":123,
""MyBoolProperty"":true,
""MyStringProperty"":""Hello"",
""MyIntField"":321,
""MyBoolField"":true,
""MyStringField"":""World""
}";

            string json;
            var    converter = new PrimitiveConverter();
            var    options   = new JsonSerializerOptions
            {
                IncludeFields = true
            };

            options.Converters.Add(converter);

            {
                var obj = new ClassWithPrimitives
                {
                    MyIntProperty    = 123,
                    MyBoolProperty   = true,
                    MyStringProperty = "Hello",
                    MyIntField       = 321,
                    MyBoolField      = true,
                    MyStringField    = "World",
                };

                json = JsonSerializer.Serialize(obj, options);

                Assert.Equal(6, converter.WriteCallCount);
                JsonTestHelper.AssertJsonEqual(expected, json);
            }
            {
                var obj = JsonSerializer.Deserialize <ClassWithPrimitives>(json, options);

                Assert.Equal(6, converter.ReadCallCount);

                Assert.Equal(123, obj.MyIntProperty);
                Assert.True(obj.MyBoolProperty);
                Assert.Equal("Hello", obj.MyStringProperty);
                Assert.Equal(321, obj.MyIntField);
                Assert.True(obj.MyBoolField);
                Assert.Equal("World", obj.MyStringField);
            }
        }
예제 #4
0
        public void PropertyBag_GetProperties_pooled()
        {
            var propertyBag = PropertyBag.GetPropertyBag <ClassWithPrimitives>();
            var container   = new ClassWithPrimitives();

            Measure.Method(() => {
                foreach (var property in propertyBag.GetProperties())
                {
                }
            })
            .WarmupCount(1)
            .MeasurementCount(100)
            .IterationsPerMeasurement(100)
            .GC()
            .Run();
        }
        public void ManagedObjectEquals_ClassWithPrimitives()
        {
            var a = new ClassWithPrimitives {
                A = 1, B = 2.3f, C = true, D = null
            };
            var b = new ClassWithPrimitives {
                A = 1, B = 2.3f, C = true, D = null
            };
            var c = new ClassWithPrimitives {
                A = 2, B = 2.3f, C = true, D = null
            };

            var managedObjectEquals = new ManagedObjectEqual();

            Assert.That(managedObjectEquals.CompareEqual(a, b), Is.True);
            Assert.That(managedObjectEquals.CompareEqual(a, c), Is.False);
        }