public bool StreamAttributeEnumOpt <T, TEnum>(TName name, T theObj, Exprs.Expression <Func <T, TEnum> > propExpr,
                                                      Predicate <TEnum> predicate = null, bool isFlags = false)
            where TEnum : struct, IComparable, IFormattable, IConvertible
        {
            Contract.Requires(ValidateNameArg(name));

            if (predicate == null)
            {
                predicate = Predicates.True <TEnum>;
            }

            bool executed = false;
            var  property = Reflection.Util.PropertyFromExpr(propExpr);

            if (IsReading)
            {
                var value = default(TEnum);
                executed = ReadAttributeEnumOpt(name, ref value);
                property.SetValue(theObj, value, null);
            }
            else if (IsWriting)
            {
                executed = WriteAttributeEnumOptOnTrue(name, (TEnum)property.GetValue(theObj, null), predicate, isFlags);
            }

            return(executed);
        }
Пример #2
0
        public static Reflect.MemberInfo MemberFromExpr <T, TProp>(Exprs.Expression <Func <T, TProp> > expr)
        {
            Contract.Requires(expr != null);
            Contract.Requires(expr.Body is Exprs.MemberExpression || expr.Body is Exprs.UnaryExpression);

            return(MemberFromLambdaExpr(expr));
        }
Пример #3
0
        public static string PropertyNameFromExpr <T, TProp>(Exprs.Expression <Func <T, TProp> > expr)
        {
            Contract.Requires <ArgumentNullException>(expr != null);
            Contract.Requires <ArgumentException>(
                expr.Body is Exprs.MemberExpression || expr.Body is Exprs.UnaryExpression);

            return(PropertyNameFromLambdaExpr(expr));
        }
Пример #4
0
        public static PropertyChangedEventArgs CreatePropertyChangedEventArgs <T, TProp>(
            Exprs.Expression <Func <T, TProp> > propertyExpr)
        {
            Contract.Requires(propertyExpr != null);
            Contract.Requires(propertyExpr.Body is Exprs.MemberExpression || propertyExpr.Body is Exprs.UnaryExpression);

            return(new PropertyChangedEventArgs(
                       Reflection.Util.PropertyFromExpr(propertyExpr).Name));
        }
Пример #5
0
        public PropertyChangedEventArgsCollection CreateArgs <T, TProp>(
            out System.ComponentModel.PropertyChangedEventArgs eventArgs,
            Exprs.Expression <Func <T, TProp> > propertyExpr)
        {
            eventArgs = Util.CreatePropertyChangedEventArgs(propertyExpr);
            mEventArgs.Add(eventArgs);

            return(this);
        }
Пример #6
0
        public static Reflect.PropertyInfo PropertyFromExpr <T, TProp>(Exprs.Expression <Func <T, TProp> > expr)
        {
            Contract.Requires(expr != null);
            Contract.Requires(expr.Body is Exprs.MemberExpression || expr.Body is Exprs.UnaryExpression);

            var member = MemberFromLambdaExpr(expr);

            Contract.Assert(member.MemberType == Reflect.MemberTypes.Property);

            return(member as Reflect.PropertyInfo);
        }
        public void StreamAttributeEnum <T, TEnum>(TName name, T theObj, Exprs.Expression <Func <T, TEnum> > propExpr,
                                                   bool isFlags = false)
            where TEnum : struct, IComparable, IFormattable, IConvertible
        {
            Contract.Requires(ValidateNameArg(name));

            var property = Reflection.Util.PropertyFromExpr(propExpr);

            if (IsReading)
            {
                var value = default(TEnum);
                ReadAttributeEnum(name, ref value);
                property.SetValue(theObj, value, null);
            }
            else if (IsWriting)
            {
                WriteAttributeEnum(name, (TEnum)property.GetValue(theObj, null), isFlags);
            }
        }
        public static bool StreamCursorBytesOpt <TDoc, TCursor, T>(this IO.TagElementStream <TDoc, TCursor, string> s, T obj, Exprs.Expression <Func <T, byte[]> > propExpr)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(s != null);

            bool executed = false;

            var property = Reflection.Util.PropertyFromExpr(propExpr);

            if (s.IsReading)
            {
                string str_value = null;
                s.ReadCursor(ref str_value);
                if (str_value.IsNotNullOrEmpty())
                {
                    var value = Text.Util.ByteStringToArray(str_value);
                    if (value.IsNotNullOrEmpty())
                    {
                        property.SetValue(obj, value, null);
                        executed = true;
                    }
                }
            }
            else if (s.IsWriting)
            {
                var value = (byte[])property.GetValue(obj, null);
                if (value.IsNotNullOrEmpty())
                {
                    string str_value = Text.Util.ByteArrayToString(value);
                    if (str_value.IsNotNullOrEmpty())
                    {
                        s.WriteCursor(str_value);
                        executed = true;
                    }
                }
            }

            return(executed);
        }