public static Binder <TSource, UISwitch> Off <TSource, TPropertyType>(this Binder <TSource, UISwitch> binder, Expression <Func <TSource, TPropertyType> > property, IConverter <TPropertyType, bool> converter = null) where TSource : class { converter = converter ?? Transmuter.Default.GetConverter <TPropertyType, bool>(); converter = new TypedConverter <TPropertyType, bool>(new ChainConverter(converter, invert)); return(binder.Off(property, converter)); }
public static Binder <TSource, TView> Hidden <TSource, TView, TPropertyType>(this Binder <TSource, TView> binder, Expression <Func <TSource, TPropertyType> > property, IConverter <TPropertyType, bool> converter = null) where TSource : class where TView : View { converter = converter ?? Transmuter.Default.GetConverter <TPropertyType, bool>(); converter = new TypedConverter <TPropertyType, bool>(new ChainConverter(converter, invert)); return(binder.Visible(property, converter)); }
public static Binder <TSource, TView> Visible <TSource, TView, TPropertyType>(this Binder <TSource, TView> binder, Expression <Func <TSource, TPropertyType> > property, IConverter <TPropertyType, bool> converter = null) where TSource : class where TView : View { converter = converter ?? Transmuter.Default.GetConverter <TPropertyType, bool>(); var toState = Transmuter.Default.GetConverter <bool, ViewStates>(); var stateconverter = new TypedConverter <TPropertyType, ViewStates>(new ChainConverter(converter, toState)); return(binder.Visibility(property, stateconverter)); }
public static T Convert <T>(this object obj) { TypedConverter converter; if (_TypedConverters.TryGetValue(typeof(T), out converter)) { TypedConverter <T> tconverter = converter as TypedConverter <T>; if (tconverter != null) { return(tconverter.Convert(obj)); } } if (obj == null) { return(default(T)); } if (obj is T) { return((T)obj); } var type = typeof(T); //if (typeof(T) == typeof(bool)) //{ // if (obj is string) // { // var str = (string)obj; // str = str.ToLower().Trim(); // if (str == "" || str == "n" || str == "no" || str == "f" || str == "false") // { // return (T)(object)false; // } // return (T)(object)true; // } //} if (type.IsEnum()) { if (obj is string) { return((T)Enum.Parse(type, obj as string)); } else if (NumericTypes.Contains(obj.GetType())) { return((T)Enum.ToObject(type, (object)System.Convert.ToUInt64(obj))); } else if (obj is Enum) { return((T)System.Convert.ChangeType(System.Convert.ToUInt64(obj), type)); } else { return(default(T)); } } //else if (obj is Enum) //{ // if (type == typeof(string)) // { // return (T)(object)obj.ToString(); // } // else if (NumericTypes.Contains(type)) // { // return (T)System.Convert.ChangeType(System.Convert.ToUInt64(obj), type); // } // else // { // return default(T); // } //} //else if (NumericTypes.Contains(type) && NumericTypes.Contains(obj.GetType())) //{ // try // { // return (T)System.Convert.ChangeType(obj, type); // } // catch // { // return default(T); // } //} //else if (type == typeof(IntPtr) && NumericTypes.Contains(obj.GetType())) //{ // try // { // long l = System.Convert.ToInt64(obj); // IntPtr p = (IntPtr)l; // return (T)(object)p; // } // catch // { // return default(T); // } //} //else if (obj is IntPtr && NumericTypes.Contains(type)) //{ // IntPtr p = (IntPtr)obj; // long l = (long)p; // try // { // return (T)System.Convert.ChangeType(l, type); // } // catch // { // return default(T); // } //} //else if (ConvertibleTypes.Contains(type) && ConvertibleTypes.Contains(obj.GetType())) //{ // try // { // return (T)System.Convert.ChangeType(obj, type); // } // catch // { // return default(T); // } //} //else if (typeof(T) == typeof(string)) //{ // return (T)(object)obj.ToString(); //} return(default(T)); }