本文整理汇总了C#中BindingBuilder.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# BindingBuilder.Bind方法的具体用法?C# BindingBuilder.Bind怎么用?C# BindingBuilder.Bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BindingBuilder
的用法示例。
在下文中一共展示了BindingBuilder.Bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuilderShouldUseTargetBindingContextForSource3
public void BuilderShouldUseTargetBindingContextForSource3()
{
const string sourcePath = "IntProperty";
var targetObj = new BindingSourceEventNotifierModel();
var builder = new BindingBuilder();
builder.Bind(targetObj, () => model => model.ObjectProperty).To(sourcePath);
IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
IBindingSource source = sources.Single().Invoke(builder);
BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
var sourceObj = new BindingSourceModel();
BindingServiceProvider.ContextManager.GetBindingContext(targetObj).Value = sourceObj;
BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
}
示例2: BuilderShouldUseTargetBindingContextForSource2
public void BuilderShouldUseTargetBindingContextForSource2()
{
const string targetPath = "Text";
const string sourcePath = "IntProperty";
var targetObj = new object();
var builder = new BindingBuilder();
builder.Bind(targetObj, targetPath).To<BindingSourceModel>(() => (model, ctx) => model.IntProperty);
IList<Func<IDataContext, IObserver>> sources = builder.GetData(BindingBuilderConstants.Sources);
IObserver source = sources.Single().Invoke(builder);
BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
var sourceObj = new BindingSourceModel();
BindingServiceProvider.ContextManager.GetBindingContext(targetObj).Value = sourceObj;
BindingParserTest.BindingSourceShouldBeValidDataContext(targetObj, source, sourcePath);
}
示例3: BuilderShouldUseValidateBehaviors
public void BuilderShouldUseValidateBehaviors()
{
var builder = new BindingBuilder();
builder.Bind(new object(), "test").To("test").Validate();
var behaviors = builder.GetData(BindingBuilderConstants.Behaviors);
behaviors.Count.ShouldEqual(2);
behaviors.OfType<ValidatesOnExceptionsBehavior>().Single().ShouldNotBeNull();
behaviors.OfType<ValidatesOnNotifyDataErrorsBehavior>().Single().ShouldNotBeNull();
}
示例4: BuilderShouldUseSourceObject1
public void BuilderShouldUseSourceObject1()
{
const string targetPath = "Text";
const string sourcePath = "IntProperty";
var targetObj = new object();
var sourceObj = new BindingSourceModel();
var builder = new BindingBuilder();
builder.Bind(targetObj, targetPath).To(sourceObj, sourcePath);
IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
IBindingSource source = sources.Single().Invoke(builder);
BindingParserTest.BindingSourceShouldBeValid(source, sourcePath, sourceObj);
}
示例5: BuilderShouldUseBindingContextExtension4
public void BuilderShouldUseBindingContextExtension4()
{
const string targetPath = "Text";
const string sourcePath = "IntProperty";
var targetObj = new object();
var builder = new BindingBuilder();
builder.Bind(targetObj, targetPath).To<BindingSourceModel>(() => model => BindingSyntaxEx.Self<object>().DataContext<BindingSourceModel>().IntProperty);
IList<Func<IDataContext, IBindingSource>> sources = builder.GetData(BindingBuilderConstants.Sources);
IBindingSource source = sources.Single().Invoke(builder);
source.Path.Path.ShouldEqual(AttachedMemberConstants.DataContext + "." + sourcePath);
}
示例6: BuilderShouldUseResourceMethod2
public void BuilderShouldUseResourceMethod2()
{
const string key = "key";
var builder = new BindingBuilder();
var sourceModel = new BindingSourceModel();
var result = new BindingSourceModel { ObjectProperty = "Test" };
BindingServiceProvider.ResourceResolver.AddMethod<string, object, BindingSourceModel>(key, (s1, s2, context) =>
{
s1.ShouldEqual(key);
s2.ShouldEqual(builder);
context.ShouldEqual(builder);
return result;
});
builder.Bind(sourceModel, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.ResourceMethod<BindingSourceModel>(key, key, builder).ObjectProperty);
var sources = builder.GetData(BindingBuilderConstants.Sources);
sources.Count.ShouldEqual(1);
sources[0].Invoke(builder).Path.Path.ShouldEqual(string.Empty);
var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
expression(builder, Empty.Array<object>()).ShouldEqual(result.ObjectProperty);
}
示例7: 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);
}
示例8: BuilderShouldUseSelfExpression1
public void BuilderShouldUseSelfExpression1()
{
var builder = new BindingBuilder();
var sourceModel = new BindingSourceModel();
builder.Bind(sourceModel, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.Self<BindingSourceModel>());
var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
builder.GetData(BindingBuilderConstants.MultiExpression).ShouldBeNull();
source.Path.IsEmpty.ShouldBeTrue();
source.GetSource(true).ShouldEqual(sourceModel);
var pathMembers = source.GetPathMembers(true);
pathMembers.LastMember.GetValue(pathMembers.PenultimateValue, null).ShouldEqual(sourceModel);
}
示例9: BuilderShouldUseConverterCulture3
public void BuilderShouldUseConverterCulture3()
{
var builder = new BindingBuilder();
builder.Bind(CultureInfo.InvariantCulture, "test").To("test").WithConverterCulture(() => o => BindingSyntaxEx.Self<CultureInfo>());
builder.GetData(BindingBuilderConstants.ConverterCulture).Invoke(builder).ShouldEqual(CultureInfo.InvariantCulture);
}
示例10: BuilderShouldUseConverterCulture2
public void BuilderShouldUseConverterCulture2()
{
Func<IDataContext, CultureInfo> culture = context => null;
var builder = new BindingBuilder();
builder.Bind(new object(), "test").To("test").WithConverterCulture(culture);
builder.GetData(BindingBuilderConstants.ConverterCulture).ShouldEqual(culture);
}
示例11: BuilderShouldUseConverterCulture1
public void BuilderShouldUseConverterCulture1()
{
var culture = CultureInfo.InvariantCulture;
var builder = new BindingBuilder();
builder.Bind(new object(), "test").To("test").WithConverterCulture(culture);
builder.GetData(BindingBuilderConstants.ConverterCulture).Invoke(builder).ShouldEqual(culture);
}
示例12: BuilderShouldUseDelayBehaviorTarget
public void BuilderShouldUseDelayBehaviorTarget()
{
var builder = new BindingBuilder();
builder.Bind(new object(), "test").To("test").WithDelay(10, true);
var behavior = builder.GetData(BindingBuilderConstants.Behaviors).OfType<DelayBindingBehavior>().Single();
behavior.Delay.ShouldEqual(10);
behavior.IsTarget.ShouldBeTrue();
}
示例13: BuilderShouldUseFallback3
public void BuilderShouldUseFallback3()
{
var builder = new BindingBuilder();
builder.Bind(builder, "test").To("test").WithFallback(() => o => BindingSyntaxEx.Self<object>());
builder.GetData(BindingBuilderConstants.Fallback).Invoke(builder).ShouldEqual(builder);
}
示例14: BuilderShouldUseFallback2
public void BuilderShouldUseFallback2()
{
Func<IDataContext, object> fallback = context => null;
var builder = new BindingBuilder();
builder.Bind(new object(), "test").To("test").WithFallback(fallback);
builder.GetData(BindingBuilderConstants.Fallback).ShouldEqual(fallback);
}
示例15: BuilderShouldUseFallback1
public void BuilderShouldUseFallback1()
{
var fallback = new object();
var builder = new BindingBuilder();
builder.Bind(new object(), "test").To("test").WithFallback(fallback);
builder.GetData(BindingBuilderConstants.Fallback).Invoke(builder).ShouldEqual(fallback);
}