Add method to override Property => Field mapping
This commit is contained in:
Родитель
8478b7d80c
Коммит
862fbf8ccc
|
@ -96,7 +96,7 @@ namespace ReactiveXamlSample
|
|||
PersonEntry _SelectedPerson;
|
||||
public PersonEntry SelectedPerson {
|
||||
get { return _SelectedPerson; }
|
||||
set { _SelectedPerson = this.RaiseAndSetIfChanged(x => _SelectedPerson, value); }
|
||||
set { _SelectedPerson = this.RaiseAndSetIfChanged(x => x.SelectedPerson, value); }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -87,6 +87,10 @@ namespace ReactiveXaml
|
|||
LoggerFactory = (prefix) => new NullLogger(prefix);
|
||||
#endif
|
||||
|
||||
// Default name for the field backing the "Foo" property => "_Foo"
|
||||
// This is used for ReactiveObject's RaiseAndSetIfChanged mixin
|
||||
GetFieldNameForPropertyNameFunc = new Func<string,string>(x => "_" + x);
|
||||
|
||||
if (InUnitTestRunner())
|
||||
{
|
||||
Console.Error.WriteLine("*** Detected Unit Test Runner, setting Scheduler to Immediate ***");
|
||||
|
@ -120,6 +124,7 @@ namespace ReactiveXaml
|
|||
public static Func<string, ILog> LoggerFactory { get; set; }
|
||||
|
||||
public static Func<UserException, RecoveryOptionResult> CustomErrorPresentationFunc { get; set; }
|
||||
public static Func<string, string> GetFieldNameForPropertyNameFunc { get; set; }
|
||||
public static RecoveryOptionResult DefaultUnitTestRecoveryResult { get; set; }
|
||||
|
||||
public static bool InUnitTestRunner()
|
||||
|
@ -153,6 +158,11 @@ namespace ReactiveXaml
|
|||
// TODO: Pop the WPF dialog here if we're not in Silverlight
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static string GetFieldNameForProperty(string PropertyName)
|
||||
{
|
||||
return GetFieldNameForPropertyNameFunc(PropertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,9 +161,10 @@ namespace ReactiveXaml
|
|||
throw new ArgumentException("Property expression must be of the form 'x => x.SomeProperty'");
|
||||
}
|
||||
|
||||
field = (typeof(TObj)).GetField("_" + prop_name, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var field_name = RxApp.GetFieldNameForProperty(prop_name);
|
||||
field = (typeof(TObj)).GetField(field_name, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field == null) {
|
||||
throw new ArgumentException("You must declare a backing field for this property named _" + prop_name);
|
||||
throw new ArgumentException("You must declare a backing field for this property named: " + prop_name);
|
||||
}
|
||||
|
||||
var field_val = field.GetValue(This);
|
||||
|
|
Загрузка…
Ссылка в новой задаче