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
            /// <summary>
            /// 属性
            /// </summary>
            /// <param name="property">属性信息</param>
            private PropertyDescriptor(PropertyInfo property)
            {
                var aliasAs = property.GetAttribute <AliasAsAttribute>(true);

                this.AliasName = aliasAs == null ? property.Name : aliasAs.Name;

                if (property.PropertyType == typeof(DateTime) || property.PropertyType == typeof(DateTime?))
                {
                    var formatAttribute = property.GetAttribute <DateTimeFormatAttribute>(true);
                    this.DateTimeFormat = formatAttribute == null ? null : formatAttribute.Format;
                }

                if (property.CanRead == true)
                {
                    this.getter = Getter.Create(property);
                }

                this.IgnoreSerialized = property.IsDefined(typeof(IgnoreSerializedAttribute));
                this.IsSupportGet     = this.getter != null;
            }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
 public static Lens <S, T, A, B> Create <S, T, A, B>(Func <S, A> getterFunc, Func <Func <A, B>, S, T> setterFunc) => new Lens <S, T, A, B>(Getter.Create(getterFunc), Setter.Create(setterFunc));