Exemplo n.º 1
0
 protected override Func <PropertyInfo, Delegate> Call <TObj, TValue>()
 {
     return(property =>
     {
         IGetter <TObj, TValue> getter = Getter.Create <TObj, TValue>(property);
         return new ProcessField <Data, TObj, TValue>(
             (Data data, TObj obj, ref TValue valuea) =>
         {
             TValue valueb = getter.Apply((TObj)data.X);
             VisitorScope <Data> result = VisitStatus.Continue;
             return result + Optional.From(new Data(valueb));
         });
     });
 }
Exemplo n.º 2
0
        public void GetterSetter()
        {
            {
                IGetter <MyClass, string> getter = Getter.Create <MyClass, string>(nameof(MyClass.MyStringProp));
                ISetter <MyClass, string> setter = Setter.Create <MyClass, string>(nameof(MyClass.MyStringProp));
                var obj = new MyClass();
                Assert.Null(getter.Apply(obj));
                setter.Apply(obj, "abc");
                Assert.Equal("abc", getter.Apply(obj));
                setter.Apply(obj, "def");
                Assert.Equal("def", getter.Apply(obj));
            }

            {
                IGetter <MyStruct, string> getter = Getter.Create <MyStruct, string>(nameof(MyStruct.MyStringProp));
                ISetter <MyStruct, string> setter = Setter.Create <MyStruct, string>(nameof(MyStruct.MyStringProp));
                var obj = new MyStruct();
                Assert.Null(getter.Apply(obj));
                setter.Apply(obj, "abc");
                Assert.Equal("abc", getter.Apply(obj));
                setter.Apply(obj, "def");
                Assert.Equal("def", getter.Apply(obj));
            }
        }