本文整理汇总了C#中BindingBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# BindingBuilder.Add方法的具体用法?C# BindingBuilder.Add怎么用?C# BindingBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BindingBuilder
的用法示例。
在下文中一共展示了BindingBuilder.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuilderShouldUseEventArgs2
public void BuilderShouldUseEventArgs2()
{
var builder = new BindingBuilder();
builder.Bind(new object(), "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.EventArgs<EventArgs>().GetType().Name);
builder.Add(BindingConstants.CurrentEventArgs, EventArgs.Empty);
var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
expression(builder, Empty.Array<object>()).ShouldEqual(EventArgs.Empty.GetType().Name);
}
示例2: BuilderShouldUseEventArgs3
public void BuilderShouldUseEventArgs3()
{
var builder = new BindingBuilder();
builder.Bind(new object(), "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.EventArgs<BindingSourceModel>().ObjectProperty);
var sourceModel = new BindingSourceModel { ObjectProperty = "test" };
builder.Add(BindingConstants.CurrentEventArgs, sourceModel);
var expression = builder.GetData(BindingBuilderConstants.MultiExpression);
expression(builder, Empty.Array<object>()).ShouldEqual(sourceModel.ObjectProperty);
}
示例3: BuilderShouldUseEventArgsForParameter2
public void BuilderShouldUseEventArgsForParameter2()
{
var builder = new BindingBuilder();
builder.Bind(new object(), "empty").To<BindingSourceModel>(() => m => m.IntProperty)
.WithCommandParameter(() => model => BindingSyntaxEx.EventArgs<EventArgs>().GetType().Name);
builder.Add(BindingConstants.CurrentEventArgs, EventArgs.Empty);
var expression = builder.GetData(BindingBuilderConstants.CommandParameter);
expression(builder).ShouldEqual(EventArgs.Empty.GetType().Name);
}
示例4: ParserShouldParseMultiExpressionWithConverter
public void ParserShouldParseMultiExpressionWithConverter()
{
const string targetPath = "Text";
const string sourcePath1 = "SourceText1";
const string sourcePath2 = "SourceText2";
const string converterName = "TestConverter";
const string binding = "Text $TestConverter(SourceText1, SourceText2)";
var target = new object();
var args = new object[] { "tset", 1 };
var sourceModel = new BindingSourceModel { IntProperty = int.MaxValue };
var bindingMock = new DataBindingMock
{
TargetAccessor = new BindingSourceAccessorMock
{
Source = new BindingSourceMock
{
GetPathMembers = b => new BindingPathMembersMock(this, BindingPath.Create("IntProperty"), new BindingMemberInfo("IntProperty", BindingSourceModel.IntPropertyInfo, typeof(BindingSourceModel)))
}
}
};
var converterMock = new ValueConverterCoreMock
{
Convert = (o, type, arg3, arg4) =>
{
type.ShouldEqual(BindingSourceModel.IntPropertyInfo.PropertyType);
o.ShouldEqual(args[0]);
arg3.ShouldEqual(args[1]);
return sourceModel;
}
};
var provider = new BindingProvider();
var resolver = new BindingResourceResolver();
BindingServiceProvider.ResourceResolver = resolver;
resolver.AddConverter(converterName, converterMock, true);
IBindingParser bindingParser = CreateBindingParser(bindingProvider: provider);
var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, target, null).Single());
context.Add(BindingConstants.Binding, bindingMock);
IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
path.Path.ShouldEqual(targetPath);
var expression = context.GetData(BindingBuilderConstants.MultiExpression);
expression(context, args).ShouldEqual(sourceModel);
var sources = context.GetData(BindingBuilderConstants.Sources);
BindingSourceShouldBeValidDataContext(target, sources[0].Invoke(context), sourcePath1);
BindingSourceShouldBeValidDataContext(target, sources[1].Invoke(context), sourcePath2);
}
示例5: ParserShouldParseExpressionWithEventArgs
public void ParserShouldParseExpressionWithEventArgs()
{
const string targetPath = "Text";
const string binding = @"Text $args";
IBindingParser bindingParser = CreateBindingParser();
var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, new object(), null).Single());
var path = context.GetData(BindingBuilderConstants.TargetPath);
path.Path.ShouldEqual(targetPath);
context.Add(BindingConstants.CurrentEventArgs, EventArgs.Empty);
var expression = context.GetData(BindingBuilderConstants.MultiExpression);
expression(context, Empty.Array<object>()).ShouldEqual(EventArgs.Empty);
}
示例6: CreateBuildersFromString
public IList<IBindingBuilder> CreateBuildersFromString(object target, string bindingExpression, IList<object> sources = null)
{
Should.NotBeNull(target, "target");
Should.NotBeNullOrWhitespace(bindingExpression, "bindingExpression");
try
{
var parserResult = Parser.Parse(bindingExpression, DataContext.Empty, target, sources);
var result = new IBindingBuilder[parserResult.Count];
for (int index = 0; index < parserResult.Count; index++)
{
var builder = new BindingBuilder(parserResult[index]);
builder.Add(BindingBuilderConstants.BuildDelegate, _buildDelegate);
result[index] = builder;
}
return result;
}
catch (Exception exception)
{
exception = new InvalidOperationException(exception.Message, exception);
var builder = new BindingBuilder();
builder.Add(BindingBuilderConstants.Target, target);
builder.Add(ProviderConstant, this);
builder.Add(ExceptionConstant, exception);
builder.Add(BindingBuilderConstants.BuildDelegate, CreateInvalidaDataBindingDelegate);
return new IBindingBuilder[] { builder };
}
}
示例7: ParserShouldParseExpressionWithBinding
public void ParserShouldParseExpressionWithBinding()
{
const string targetPath = "Text";
const string binding = @"Text $binding";
var dataContext = new DataContext();
var bindingMock = new DataBindingMock { GetContext = () => dataContext };
IBindingParser bindingParser = CreateBindingParser();
var context = new BindingBuilder(bindingParser.Parse(new object(), binding, null, null).Single());
var path = context.GetData(BindingBuilderConstants.TargetPath);
path.Path.ShouldEqual(targetPath);
context.Add(BindingConstants.Binding, bindingMock);
var expression = context.GetData(BindingBuilderConstants.MultiExpression);
expression(context, Empty.Array<object>()).ShouldEqual(bindingMock);
}