當前位置: 首頁>>代碼示例>>C#>>正文


C# BindingBuilder.GetOrAddBehaviors方法代碼示例

本文整理匯總了C#中BindingBuilder.GetOrAddBehaviors方法的典型用法代碼示例。如果您正苦於以下問題:C# BindingBuilder.GetOrAddBehaviors方法的具體用法?C# BindingBuilder.GetOrAddBehaviors怎麽用?C# BindingBuilder.GetOrAddBehaviors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BindingBuilder的用法示例。


在下文中一共展示了BindingBuilder.GetOrAddBehaviors方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BuilderShouldUseGetErrorsMethod4

        public void BuilderShouldUseGetErrorsMethod4()
        {
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            builder.Bind(sourceModel, "empty").To(sourceModel, () => model => BindingSyntaxEx.GetErrors("1", "2").Concat(BindingSyntaxEx.GetErrors(model.ObjectProperty)));


            var sources = builder.GetData(BindingBuilderConstants.Sources).Select(func => func(builder)).ToArray();
            sources[0].GetSource(true).ShouldEqual(sourceModel);
            sources[1].GetSource(true).ShouldEqual(sourceModel);
            if (sources[0].Path.IsEmpty)
                sources[1].Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));
            else
                sources[0].Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));

            var behaviors = builder.GetOrAddBehaviors().OfType<NotifyDataErrorsAggregatorBehavior>().ToArray();
            builder.AddOrUpdate(BindingConstants.Binding, new DataBindingMock { Behaviors = behaviors });
            var behavior = behaviors.Single(b => !b.ErrorPaths.IsNullOrEmpty());
            behavior.ErrorPaths.SequenceEqual(new[] { "1", "2" }).ShouldBeTrue();

            behaviors.ForEach(aggregatorBehavior => aggregatorBehavior.Errors = new[] { "1" });
            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            var errors = (IEnumerable<object>)expression(builder, new object[] { sourceModel, sourceModel });
            errors.SequenceEqual(behaviors[0].Errors.Concat(behaviors[1].Errors)).ShouldBeTrue();
        }
開發者ID:windygu,項目名稱:MugenMvvmToolkit,代碼行數:25,代碼來源:BindingSyntaxExtensionsTest.cs

示例2: BuilderShouldUseGetErrorsMethod3

        public void BuilderShouldUseGetErrorsMethod3()
        {
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            builder.Bind(sourceModel, "empty").To(sourceModel, () => model => BindingSyntaxEx.GetErrors("1", "2", model.ObjectProperty));

            var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
            source.Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));
            source.GetSource(true).ShouldEqual(sourceModel);

            var behavior = builder.GetOrAddBehaviors().OfType<NotifyDataErrorsAggregatorBehavior>().Single();
            behavior.ErrorPaths.SequenceEqual(new[] { "1", "2" }).ShouldBeTrue();
            builder.AddOrUpdate(BindingConstants.Binding, new DataBindingMock { Behaviors = new[] { behavior } });

            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            behavior.Errors = new List<object> { "test" };
            expression(builder, new object[] { sourceModel }).ShouldEqual(behavior.Errors);
        }
開發者ID:windygu,項目名稱:MugenMvvmToolkit,代碼行數:18,代碼來源:BindingSyntaxExtensionsTest.cs

示例3: BuilderShouldUseGetErrorsMethod1

        public void BuilderShouldUseGetErrorsMethod1()
        {
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            builder.Bind(sourceModel, "empty").To(sourceModel, () => (model, ctx) => ctx.GetErrors());

            var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
            source.Path.IsEmpty.ShouldBeTrue();
            source.GetActualSource(true).ShouldEqual(sourceModel);

            var behavior = builder.GetOrAddBehaviors().OfType<NotifyDataErrorsAggregatorBehavior>().Single();
            behavior.ErrorPaths.IsNullOrEmpty().ShouldBeTrue();
            builder.AddOrUpdate(BindingConstants.Binding, new DataBindingMock { Behaviors = new[] { behavior } });

            var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
            behavior.Errors = new List<object> { "test" };
            expression(builder, new object[] { sourceModel }).ShouldEqual(behavior.Errors);
        }
開發者ID:sami1971,項目名稱:MugenMvvmToolkit,代碼行數:18,代碼來源:BindingSyntaxExtensionsTest.cs

示例4: BuilderShouldUseGetErrorsMethodForParameter2

        public void BuilderShouldUseGetErrorsMethodForParameter2()
        {
            var builder = new BindingBuilder();
            var sourceModel = new BindingSourceModel();
            builder.Bind(sourceModel, "empty").To(sourceModel, () => model => model.IntProperty)
                .WithCommandParameter(() => model => BindingSyntaxEx.GetErrors("1", "2"));

            var behavior = builder.GetOrAddBehaviors().OfType<NotifyDataErrorsAggregatorBehavior>().Single();
            behavior.ErrorPaths.SequenceEqual(new[] { "1", "2" }).ShouldBeTrue();
            builder.AddOrUpdate(BindingConstants.Binding, new DataBindingMock { Behaviors = new[] { behavior } });

            var expression = builder.GetData(BindingBuilderConstants.CommandParameter);
            behavior.Errors = new List<object> { "test" };
            expression(builder).ShouldEqual(behavior.Errors);
        }
開發者ID:windygu,項目名稱:MugenMvvmToolkit,代碼行數:15,代碼來源:BindingSyntaxExtensionsTest.cs

示例5: BuilderShouldUseGetErrorsMethodForParameter1

        public void BuilderShouldUseGetErrorsMethodForParameter1()
        {
            for (int i = 0; i < 4; i++)
            {
                var builder = new BindingBuilder();
                var sourceModel = new BindingSourceModel();
                builder.Bind(sourceModel, "empty").To(sourceModel, () => (model, ctx) => model.IntProperty)
                    .WithCommandParameter(() => (model, ctx) => ctx.GetErrors());

                var behavior = builder.GetOrAddBehaviors().OfType<NotifyDataErrorsAggregatorBehavior>().Single();
                behavior.ErrorPaths.IsNullOrEmpty().ShouldBeTrue();
                builder.AddOrUpdate(BindingConstants.Binding, new DataBindingMock { Behaviors = new[] { behavior } });

                var expression = builder.GetData(BindingBuilderConstants.CommandParameter);
                behavior.Errors = new List<object> { "test" };
                expression(builder).ShouldEqual(behavior.Errors);
            }
        }
開發者ID:sami1971,項目名稱:MugenMvvmToolkit,代碼行數:18,代碼來源:BindingSyntaxExtensionsTest.cs


注:本文中的BindingBuilder.GetOrAddBehaviors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。