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); }
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)); }
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)); }
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)); }
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); }
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); }