当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionObserver类代码示例

本文整理汇总了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);
        }
开发者ID:mikel785,项目名称:Perspex,代码行数:34,代码来源:ExpressionObserverTests_DataValidation.cs

示例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;
        }
开发者ID:hacklex,项目名称:Perspex,代码行数:29,代码来源:XamlBinding.cs

示例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);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:7,代码来源:ExpressionObserverTests_Property.cs

示例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);
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:7,代码来源:ExpressionObserverTests_Property.cs

示例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);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:7,代码来源:ExpressionObserverTests_Property.cs

示例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);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:8,代码来源:ExpressionObserverTests_Indexer.cs

示例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);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:8,代码来源:ExpressionObserverTests_Indexer.cs

示例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);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:8,代码来源:ExpressionObserverTests_Property.cs

示例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);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:8,代码来源:ExpressionObserverTests_Property.cs

示例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);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:8,代码来源:ExpressionObserverTests_Indexer.cs

示例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);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:8,代码来源:ExpressionObserverTests_Indexer.cs

示例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);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:8,代码来源:ExpressionObserverTests_Indexer.cs

示例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);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:8,代码来源:ExpressionObserverTests_Indexer.cs

示例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);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:8,代码来源:ExpressionObserverTests_Indexer.cs

示例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);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:8,代码来源:ExpressionObserverTests_PerspexProperty.cs


注:本文中的ExpressionObserver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。