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


C# ExpressionObserver.SetValue方法代码示例

本文整理汇总了C#中ExpressionObserver.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionObserver.SetValue方法的具体用法?C# ExpressionObserver.SetValue怎么用?C# ExpressionObserver.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExpressionObserver的用法示例。


在下文中一共展示了ExpressionObserver.SetValue方法的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: Should_Set_Simple_Property_Value

        public void Should_Set_Simple_Property_Value()
        {
            var data = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "Foo");

            target.SetValue("bar");

            Assert.Equal("foo", data.Foo);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:9,代码来源:ExpressionObserverTests_SetValue.cs

示例3: Exception_Validation_Sends_ValidationUpdate

 public void Exception_Validation_Sends_ValidationUpdate()
 {
     var data = new ExceptionTest { MustBePositive = 5 };
     var observer = new ExpressionObserver(data, nameof(data.MustBePositive), false);
     var validationMessageFound = false;
     observer.Where(o => o is IValidationStatus).Subscribe(_ => validationMessageFound = true);
     observer.SetValue(-5);
     Assert.True(validationMessageFound);
 }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:9,代码来源:ExpressionObserverTests_Validation.cs

示例4: Should_Set_Value_On_Simple_Property_Chain

        public void Should_Set_Value_On_Simple_Property_Chain()
        {
            var data = new Class1 { Foo = new Class2 { Bar = "bar" } };
            var target = new ExpressionObserver(data, "Foo.Bar");

            target.SetValue("foo");

            Assert.Equal("foo", data.Foo.Bar);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:9,代码来源:ExpressionObserverTests_SetValue.cs

示例5: Should_Not_Try_To_Set_Value_On_Broken_Chain

        public void Should_Not_Try_To_Set_Value_On_Broken_Chain()
        {
            var data = new Class1 { Foo = new Class2 { Bar = "bar" } };
            var target = new ExpressionObserver(data, "Foo.Bar");

            // Ensure the ExpressionObserver's subscriptions are kept active.
            target.OfType<string>().Subscribe(x => { });

            data.Foo = null;

            Assert.False(target.SetValue("foo"));
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:12,代码来源:ExpressionObserverTests_SetValue.cs

示例6: Exception_Validation_Sends_DataValidationError

        public void Exception_Validation_Sends_DataValidationError()
        {
            var data = new ExceptionTest { MustBePositive = 5 };
            var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true);
            var validationMessageFound = false;

            observer.OfType<BindingNotification>()
                .Where(x => x.ErrorType == BindingErrorType.DataValidationError)
                .Subscribe(_ => validationMessageFound = true);
            observer.SetValue(-5);

            Assert.True(validationMessageFound);
        }
开发者ID:mikel785,项目名称:Perspex,代码行数:13,代码来源:ExpressionObserverTests_DataValidation.cs

示例7: SetValue_Should_Return_False_For_Missing_Property

        public void SetValue_Should_Return_False_For_Missing_Property()
        {
            var data = new Class1 { Next = new WithoutBar()};
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.False(target.SetValue("baz"));
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:7,代码来源:ExpressionObserverTests_Property.cs

示例8: SetValue_Should_Set_Property_At_The_End_Of_Chain

        public void SetValue_Should_Set_Property_At_The_End_Of_Chain()
        {
            var data = new Class1 { Next = new Class2 { Bar = "bar" } };
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.True(target.SetValue("baz"));
            Assert.Equal("baz", ((Class2)data.Next).Bar);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:8,代码来源:ExpressionObserverTests_Property.cs

示例9: SetValue_Should_Throw

        public void SetValue_Should_Throw()
        {
            var data = new { Foo = "foo" };
            var target = new ExpressionObserver(data, "!Foo");

            Assert.Throws<NotSupportedException>(() => target.SetValue("bar"));
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:7,代码来源:ExpressionObserverTests_Negation.cs

示例10: Should_Set_NonIntegerIndexer

        public void Should_Set_NonIntegerIndexer()
        {
            var data = new { Foo = new NonIntegerIndexer() };
            data.Foo["foo"] = "bar";
            data.Foo["baz"] = "qux";

            var target = new ExpressionObserver(data, "Foo[foo]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("bar2"));
            }
            
            Assert.Equal("bar2", data.Foo["foo"]);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:15,代码来源:ExpressionObserverTests_Indexer.cs

示例11: Should_Add_NewDictionaryEntry

        public void Should_Add_NewDictionaryEntry()
        {
            var data = new
            {
                Foo = new Dictionary<string, int>
                {
                    {"foo", 1 }
                }
            };
            
            var target = new ExpressionObserver(data, "Foo[bar]");
            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue(4));
            }

            Assert.Equal(4, data.Foo["bar"]);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:18,代码来源:ExpressionObserverTests_Indexer.cs

示例12: Should_SetArrayIndex

        public void Should_SetArrayIndex()
        {
            var data = new { Foo = new[] { "foo", "bar" } };
            var target = new ExpressionObserver(data, "Foo[1]");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("baz"));
            }

            Assert.Equal("baz", data.Foo[1]);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:12,代码来源:ExpressionObserverTests_Indexer.cs

示例13: SetValue_Should_Set_Simple_Property_Value

        public void SetValue_Should_Set_Simple_Property_Value()
        {
            var data = new Class1 { Foo = "foo" };
            var target = new ExpressionObserver(data, "Foo");

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("bar"));
            }

            Assert.Equal("bar", data.Foo);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:12,代码来源:ExpressionObserverTests_Property.cs

示例14: SetValue_Should_Return_False_For_Missing_Object

        public void SetValue_Should_Return_False_For_Missing_Object()
        {
            var data = new Class1();
            var target = new ExpressionObserver(data, "Next.Bar");

            Assert.False(target.SetValue("baz"));
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:7,代码来源:ExpressionObserverTests_Property.cs

示例15: SetValue_Should_Notify_New_Value_Without_Inpc

        public void SetValue_Should_Notify_New_Value_Without_Inpc()
        {
            var data = new Class1();
            var target = new ExpressionObserver(data, "Bar");
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));
            target.SetValue("bar");

            Assert.Equal(new[] { null, "bar" }, result);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:11,代码来源:ExpressionObserverTests_Property.cs


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