Пример #1
0
        public void FastReflectionProperties()
        {
            var fastReflection = new FastReflection();
            var testValue      = new MockValue();

            Assert.AreEqual(1, fastReflection.GetProperty(testValue, nameof(MockValue.Foo)));
            Assert.AreEqual(2, fastReflection.GetProperty(testValue, nameof(MockValue.Bar)));



            try
            {
                fastReflection.GetProperty(testValue, nameof(MockValue.Boo));
                Assert.Fail();
            }
            catch (MemberAccessException)
            {
            }
            catch
            {
                Assert.Fail();
            }



            try
            {
                fastReflection.GetProperty(testValue, "Buzz");
                Assert.Fail();
            }
            catch (MemberAccessException)
            {
            }
            catch
            {
                Assert.Fail();
            }


            testValue = new MockValue();
            fastReflection.SetProperty(testValue, nameof(MockValue.Foo), 123);
            Assert.AreEqual(123, fastReflection.GetProperty(testValue, nameof(MockValue.Foo)));



            try
            {
                fastReflection.SetProperty(testValue, nameof(MockValue.Bar), 123);
                Assert.Fail();
            }
            catch (MemberAccessException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }
Пример #2
0
 public static IOperation GenerateAutoMergeOperation <T, TProperty, TMergeKey>(this T _this, string propertyName, TProperty newValue, TProperty oldValue, TMergeKey mergeKey, TimeSpan timeSpan)
 {
     return(new MergeableOperation <TProperty>(
                x => { FastReflection.SetProperty(_this, propertyName, x); },
                newValue,
                oldValue, new ThrottleMergeJudge <TMergeKey>(mergeKey, timeSpan)));
 }
Пример #3
0
        public IPropertyBuilder Register <T>(string propertyName)
        {
            if (FastReflection.ExistsSetter(Object, propertyName) is false)
            {
                RegisterReadOnly(() => FastReflection.GetProperty <T>(Object, propertyName));
            }
            else
            {
                Register(
                    () => FastReflection.GetProperty <T>(Object, propertyName),
                    (x) =>
                {
                    FastReflection.SetProperty(Object, propertyName, x);
                });
            }

            _properties[_properties.Count - 1].Name = propertyName;

            return(this);
        }