本文整理汇总了C#中ExpressionObserver类的典型用法代码示例。如果您正苦于以下问题:C# ExpressionObserver类的具体用法?C# ExpressionObserver怎么用?C# ExpressionObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionObserver类属于命名空间,在下文中一共展示了ExpressionObserver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validation_Plugins_Send_Correct_Notifications
public void Validation_Plugins_Send_Correct_Notifications()
{
var data = new IndeiTest();
var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
var result = new List<object>();
observer.Subscribe(x => result.Add(x));
observer.SetValue(5);
observer.SetValue(-5);
observer.SetValue("foo");
observer.SetValue(5);
Assert.Equal(new[]
{
new BindingNotification(0),
// Value is notified twice as ErrorsChanged is always called by IndeiTest.
new BindingNotification(5),
new BindingNotification(5),
// Value is first signalled without an error as validation hasn't been updated.
new BindingNotification(-5),
new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, -5),
// Exception is thrown by trying to set value to "foo".
new BindingNotification(
new ArgumentException("Object of type 'System.String' cannot be converted to type 'System.Int32'."),
BindingErrorType.DataValidationError),
// Value is set then validation is updated.
new BindingNotification(new Exception("Must be positive"), BindingErrorType.DataValidationError, 5),
new BindingNotification(5),
}, result);
}
示例2: CreateExpressionObserver
public ExpressionObserver CreateExpressionObserver(
IObservablePropertyBag instance,
PerspexProperty property)
{
IObservable<object> dataContext = null;
if (property != Control.DataContextProperty)
{
dataContext = instance.GetObservable(Control.DataContextProperty);
}
else
{
var parent = instance.InheritanceParent as IObservablePropertyBag;
if (parent != null)
{
dataContext = parent.GetObservable(Control.DataContextProperty);
}
}
if (dataContext != null)
{
var result = new ExpressionObserver(null, SourcePropertyPath);
dataContext.Subscribe(x => result.Root = x);
return result;
}
return null;
}
示例3: Should_Get_Simple_Property_Value_Type
public void Should_Get_Simple_Property_Value_Type()
{
var data = new { Foo = "foo" };
var target = new ExpressionObserver(data, "Foo");
Assert.Equal(typeof(string), target.ResultType);
}
示例4: Should_Have_Null_ResultType_For_Broken_Chain
public void Should_Have_Null_ResultType_For_Broken_Chain()
{
var data = new { Foo = new { Bar = 1 } };
var target = new ExpressionObserver(data, "Foo.Bar.Baz");
Assert.Null(target.ResultType);
}
示例5: Should_Get_Simple_Property_Chain_Type
public void Should_Get_Simple_Property_Chain_Type()
{
var data = new { Foo = new { Bar = new { Baz = "baz" } } };
var target = new ExpressionObserver(data, "Foo.Bar.Baz");
Assert.Equal(typeof(string), target.ResultType);
}
示例6: Should_Get_UnsetValue_For_Invalid_Array_Index
public async void Should_Get_UnsetValue_For_Invalid_Array_Index()
{
var data = new { Foo = new[] { "foo", "bar" } };
var target = new ExpressionObserver(data, "Foo[invalid]");
var result = await target.Take(1);
Assert.Equal(AvaloniaProperty.UnsetValue, result);
}
示例7: Should_Get_Array_Value
public async void Should_Get_Array_Value()
{
var data = new { Foo = new [] { "foo", "bar" } };
var target = new ExpressionObserver(data, "Foo[1]");
var result = await target.Take(1);
Assert.Equal("bar", result);
}
示例8: Should_Return_UnsetValue_For_Observable_Root_Null
public async void Should_Return_UnsetValue_For_Observable_Root_Null()
{
var data = new Class3 { Foo = "foo" };
var target = new ExpressionObserver(Observable.Return(default(object)), "Foo");
var result = await target.Take(1);
Assert.Equal(AvaloniaProperty.UnsetValue, result);
}
示例9: Should_Return_UnsetValue_For_Root_UnsetValue
public async void Should_Return_UnsetValue_For_Root_UnsetValue()
{
var data = new Class3 { Foo = "foo" };
var target = new ExpressionObserver(AvaloniaProperty.UnsetValue, "Foo");
var result = await target.Take(1);
Assert.Equal(AvaloniaProperty.UnsetValue, result);
}
示例10: List_Out_Of_Bounds_Should_Return_UnsetValue
public async void List_Out_Of_Bounds_Should_Return_UnsetValue()
{
var data = new { Foo = new List<string> { "foo", "bar" } };
var target = new ExpressionObserver(data, "Foo[2]");
var result = await target.Take(1);
Assert.Equal(PerspexProperty.UnsetValue, result);
}
示例11: Array_With_Wrong_Dimensions_Should_Return_UnsetValue
public async void Array_With_Wrong_Dimensions_Should_Return_UnsetValue()
{
var data = new { Foo = new[] { "foo", "bar" } };
var target = new ExpressionObserver(data, "Foo[1,2]");
var result = await target.Take(1);
Assert.Equal(PerspexProperty.UnsetValue, result);
}
示例12: Array_Out_Of_Bounds_Should_Return_UnsetValue
public async void Array_Out_Of_Bounds_Should_Return_UnsetValue()
{
var data = new { Foo = new[] { "foo", "bar" } };
var target = new ExpressionObserver(data, "Foo[2]");
var result = await target.Take(1);
Assert.Equal(AvaloniaProperty.UnsetValue, result);
}
示例13: Should_Get_UnsetValue_For_Invalid_Dictionary_Index
public async void Should_Get_UnsetValue_For_Invalid_Dictionary_Index()
{
var data = new { Foo = new Dictionary<int, string> { { 1, "foo" } } };
var target = new ExpressionObserver(data, "Foo[invalid]");
var result = await target.Take(1);
Assert.Equal(AvaloniaProperty.UnsetValue, result);
}
示例14: Should_Get_UnsetValue_For_Object_Without_Indexer
public async void Should_Get_UnsetValue_For_Object_Without_Indexer()
{
var data = new { Foo = 5 };
var target = new ExpressionObserver(data, "Foo[noindexer]");
var result = await target.Take(1);
Assert.Equal(AvaloniaProperty.UnsetValue, result);
}
示例15: Should_Get_Simple_Property_Value
public async void Should_Get_Simple_Property_Value()
{
var data = new Class1();
var target = new ExpressionObserver(data, "Foo");
var result = await target.Take(1);
Assert.Equal("foo", result);
}