Last active
August 29, 2015 14:21
-
-
Save mntone/b2fcfeff091db33be611 to your computer and use it in GitHub Desktop.
(en) ReactiveProperty factory extensions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file is under The MIT License (MIT). | |
using Reactive.Bindings; | |
using System; | |
using System.Linq.Expressions; | |
using System.Reactive.Concurrency; | |
namespace Mntone.Reactive.Bindings | |
{ | |
public static class ReactiveProperty2 | |
{ | |
#region Int16 section | |
public static ReactiveProperty<string> FromInt16<TTarget>( | |
TTarget target, | |
Expression<Func<TTarget, short>> propertySelector, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return FromInt16(target, propertySelector, UIDispatcherScheduler.Default, mode, ignoreValidationErrorValue); | |
} | |
public static ReactiveProperty<string> FromInt16<TTarget>( | |
TTarget target, | |
Expression<Func<TTarget, short>> propertySelector, | |
IScheduler raiseEventScheduler, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return ReactiveProperty.FromObject( | |
target, | |
propertySelector, | |
x => x.ToString(), | |
x => string.IsNullOrWhiteSpace(x) || (x.Length == 1 && x[0] == '-') | |
? (short)0 | |
: Convert.ToInt16(x), | |
raiseEventScheduler, | |
mode, | |
ignoreValidationErrorValue); | |
} | |
#endregion | |
#region Int32 section | |
public static ReactiveProperty<string> FromInt32<TTarget>( | |
TTarget target, | |
Expression<Func<TTarget, int>> propertySelector, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return FromInt32(target, propertySelector, UIDispatcherScheduler.Default, mode, ignoreValidationErrorValue); | |
} | |
public static ReactiveProperty<string> FromInt32<TTarget>( | |
TTarget target, | |
Expression<Func<TTarget, int>> propertySelector, | |
IScheduler raiseEventScheduler, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return ReactiveProperty.FromObject( | |
target, | |
propertySelector, | |
x => x.ToString(), | |
x => string.IsNullOrWhiteSpace(x) || (x.Length == 1 && x[0] == '-') | |
? 0 | |
: Convert.ToInt32(x), | |
raiseEventScheduler, | |
mode, | |
ignoreValidationErrorValue); | |
} | |
#endregion | |
#region Int64 section | |
public static ReactiveProperty<string> FromInt64<TTarget>( | |
TTarget target, | |
Expression<Func<TTarget, long>> propertySelector, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return FromInt64(target, propertySelector, UIDispatcherScheduler.Default, mode, ignoreValidationErrorValue); | |
} | |
public static ReactiveProperty<string> FromInt64<TTarget>( | |
TTarget target, | |
Expression<Func<TTarget, long>> propertySelector, | |
IScheduler raiseEventScheduler, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return ReactiveProperty.FromObject( | |
target, | |
propertySelector, | |
x => x.ToString(), | |
x => string.IsNullOrWhiteSpace(x) || (x.Length == 1 && x[0] == '-') | |
? 0 | |
: Convert.ToInt64(x), | |
raiseEventScheduler, | |
mode, | |
ignoreValidationErrorValue); | |
} | |
#endregion | |
#region Enum (derived from Int16) for RxProp<Int32> section | |
public static ReactiveProperty<int> FromEnumDerivedFromInt16ToReactivePropertyOfInt32<TTarget, TEnumProperty>( | |
TTarget target, | |
Expression<Func<TTarget, TEnumProperty>> propertySelector, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return FromEnumDerivedFromInt16ToReactivePropertyOfInt32(target, propertySelector, UIDispatcherScheduler.Default, mode, ignoreValidationErrorValue); | |
} | |
public static ReactiveProperty<int> FromEnumDerivedFromInt16ToReactivePropertyOfInt32<TTarget, TEnumProperty>( | |
TTarget target, | |
Expression<Func<TTarget, TEnumProperty>> propertySelector, | |
IScheduler raiseEventScheduler, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return ReactiveProperty.FromObject( | |
target, | |
propertySelector, | |
x => Convert.ToInt32(x), | |
x => (TEnumProperty)((object)Convert.ToInt16((object)x)), | |
raiseEventScheduler, | |
mode, | |
ignoreValidationErrorValue); | |
} | |
#endregion | |
#region Enum (derived from Int32) for RxProp<Int32> section | |
public static ReactiveProperty<int> FromEnumDerivedFromInt32ToReactivePropertyOfInt32<TTarget, TEnumProperty>( | |
TTarget target, | |
Expression<Func<TTarget, TEnumProperty>> propertySelector, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return FromEnumDerivedFromInt32ToReactivePropertyOfInt32(target, propertySelector, UIDispatcherScheduler.Default, mode, ignoreValidationErrorValue); | |
} | |
public static ReactiveProperty<int> FromEnumDerivedFromInt32ToReactivePropertyOfInt32<TTarget, TEnumProperty>( | |
TTarget target, | |
Expression<Func<TTarget, TEnumProperty>> propertySelector, | |
IScheduler raiseEventScheduler, | |
ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe, | |
bool ignoreValidationErrorValue = false) | |
{ | |
return ReactiveProperty.FromObject( | |
target, | |
propertySelector, | |
x => Convert.ToInt32(x), | |
x => (TEnumProperty)((object)x), | |
raiseEventScheduler, | |
mode, | |
ignoreValidationErrorValue); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment