Exemple #1
0
        public object GetPropertyImmediateReflection([NotNull] object obj)
        {
            ImmediateType     accessor = ImmediateReflection.TypeAccessor.Get(obj.GetType());
            ImmediateProperty property = accessor.GetProperty(UIntArrayPropertyName);

            return(property?.GetValue(obj));
        }
 public void SetImmediateProperty_Property()
 {
     ImmediateProperty.SetValue(BenchmarkObject, ValueToSet);
     ImmediateProperty2.SetValue(BenchmarkObject2, ValueToSet2);
     ImmediateProperty3.SetValue(BenchmarkObject3, ValueToSet3);
     ImmediateProperty4.SetValue(BenchmarkObject4, ValueToSet4);
 }
        public void SetPropertyImmediateReflection([NotNull] object obj)
        {
            ImmediateType     accessor = ImmediateReflection.TypeAccessor.Get(obj.GetType());
            ImmediateProperty property = accessor.GetProperty(UIntArrayPropertyName);

            property?.SetValue(obj, ValueToSet);
        }
Exemple #4
0
        public void ImmediatePropertySerialization()
        {
            var property = new ImmediateProperty(PublicReferenceTypePublicGetSetPropertyPropertyInfo);
            ImmediateProperty deserializedProperty = SerializeAndDeserialize(property);

            Assert.AreEqual(nameof(PublicReferenceTypeTestClass.PublicPropertyGetSet), deserializedProperty.Name);
            Assert.AreEqual(typeof(PublicReferenceTypeTestClass), deserializedProperty.DeclaringType);
            Assert.AreEqual(typeof(TestObject), deserializedProperty.PropertyType);
            Assert.AreEqual(PublicReferenceTypePublicGetSetPropertyPropertyInfo, deserializedProperty.PropertyInfo);
            Assert.IsTrue(deserializedProperty.CanRead);
            Assert.IsTrue(deserializedProperty.CanWrite);
        }
        public void GetPropertyWithNew()
        {
            var immediateProperties = new ImmediateProperties(new[] { ChildTypeRedefinitionClassPublicGetPropertyPropertyInfo, BaseClassPublicGetPropertyPropertyInfo });
            var expectedProperty    = new ImmediateProperty(ChildTypeRedefinitionClassPublicGetPropertyPropertyInfo);

            Assert.AreEqual(expectedProperty, immediateProperties[nameof(ChildTypeRedefinitionTestClass.Property)]);
            Assert.AreEqual(expectedProperty, immediateProperties.GetProperty(nameof(ChildTypeRedefinitionTestClass.Property)));

            immediateProperties = new ImmediateProperties(new[] { BaseClassPublicGetPropertyPropertyInfo, ChildTypeRedefinitionClassPublicGetPropertyPropertyInfo });
            Assert.AreEqual(expectedProperty, immediateProperties[nameof(ChildTypeRedefinitionTestClass.Property)]);
            Assert.AreEqual(expectedProperty, immediateProperties.GetProperty(nameof(ChildTypeRedefinitionTestClass.Property)));
        }
Exemple #6
0
        public void GetImmediateProperty()
        {
            Type testType = typeof(PublicValueTypeTestClass);
            ImmediateProperty property = testType.GetImmediateProperty(nameof(PublicValueTypeTestClass.PublicPropertyGetSet));

            Assert.IsNotNull(property);
            Assert.AreEqual(PublicValueTypePublicGetSetPropertyPropertyInfo, property.PropertyInfo);

            property = testType.GetImmediateProperty("PrivatePropertyGetSet", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(property);
            Assert.AreEqual(PublicValueTypePrivateGetSetPropertyPropertyInfo, property.PropertyInfo);

            property = testType.GetImmediateProperty("NotExists");
            Assert.IsNull(property);
        }
        public void GetProperty()
        {
            var immediateProperties = new ImmediateProperties(SmallObjectPropertyInfos);
            var expectedProperty    = new ImmediateProperty(SmallObjectTestProperty1PropertyInfo);

            Assert.AreEqual(expectedProperty, immediateProperties[nameof(SmallObject.TestProperty1)]);
            Assert.AreEqual(expectedProperty, immediateProperties.GetProperty(nameof(SmallObject.TestProperty1)));

            Assert.IsNull(immediateProperties["NotExists"]);
            Assert.IsNull(immediateProperties.GetProperty("NotExists"));

            // ReSharper disable InconsistentNaming
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => { var _ = immediateProperties[null]; });
            Assert.Throws <ArgumentNullException>(() => { var _ = immediateProperties.GetProperty(null); });
            // ReSharper restore AssignNullToNotNullAttribute
            // ReSharper restore InconsistentNaming
        }
 public string GetImmediateProperty_Property()
 {
     return($"{(string)ImmediateProperty.GetValue(BenchmarkObject)}{(int)ImmediateProperty2.GetValue(BenchmarkObject2)}{(double)ImmediateProperty3.GetValue(BenchmarkObject3)}{(short)ImmediateProperty4.GetValue(BenchmarkObject4)}");
 }
Exemple #9
0
 public string GetImmediateProperty_Property()
 {
     return((string)ImmediateProperty.GetValue(BenchmarkObject));
 }
Exemple #10
0
 public void SetImmediateProperty_Property()
 {
     ImmediateProperty.SetValue(BenchmarkObject, ValueToSet);
 }