本文整理汇总了C#中BindingBuilder类的典型用法代码示例。如果您正苦于以下问题:C# BindingBuilder类的具体用法?C# BindingBuilder怎么用?C# BindingBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BindingBuilder类属于命名空间,在下文中一共展示了BindingBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadName
private void ReadName(XElement element, BindingBuilder<object> builder)
{
var nameAttribute = element.Attribute("name");
if (nameAttribute != null)
builder.Named(nameAttribute.Value);
}
示例2: ReadScope
private void ReadScope(XElement element, BindingBuilder<object> builder)
{
XAttribute scopeAttribute = element.Attribute("scope");
if (scopeAttribute == null || String.IsNullOrEmpty(scopeAttribute.Value))
{
builder.InTransientScope();
return;
}
string value = scopeAttribute.Value.ToLower();
switch (value)
{
case "transient":
builder.InTransientScope();
break;
case "singleton":
builder.InSingletonScope();
break;
case "thread":
builder.InThreadScope();
break;
case "request":
builder.InRequestScope();
break;
default:
throw new ConfigurationErrorsException(String.Format("The 'bind' element has an unknown value '{0}' for its 'scope' attribute. Valid values are transient, singleton, thread, and request.", value));
}
}
示例3: ReadMetadata
private void ReadMetadata(XElement element, BindingBuilder<object> builder)
{
foreach (XElement metadataElement in element.Elements("metadata"))
{
XAttribute keyAttribute = metadataElement.RequiredAttribute("key");
XAttribute valueAttribute = metadataElement.RequiredAttribute("value");
builder.WithMetadata(keyAttribute.Value, valueAttribute.Value);
}
}
示例4: BuilderShouldUseTargetBindingContextForSource4
public void BuilderShouldUseTargetBindingContextForSource4()
{
const string sourcePath = "IntProperty";
var targetObj = new BindingSourceEventNotifierModel();
var builder = new BindingBuilder();
builder.Bind(targetObj, () => model => model.ObjectProperty).To<BindingSourceModel>(() => model => model.IntProperty);
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);
}
示例5: 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);
}
示例6: ParserShouldParseSingleExpression1
public void ParserShouldParseSingleExpression1()
{
const string targetPath = "Text";
const string sourcePath = "SourceText";
const string binding = "Text SourceText";
var target = new object();
IBindingParser bindingParser = CreateBindingParser();
var context = new BindingBuilder(bindingParser.Parse(target, binding, null, null).Single());
IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
path.Path.ShouldEqual(targetPath);
var sources = context.GetData(BindingBuilderConstants.Sources);
IObserver source = sources.Single().Invoke(context);
BindingSourceShouldBeValidDataContext(target, source, sourcePath);
}
示例7: ParserShouldParseSingleExpression2
public void ParserShouldParseSingleExpression2()
{
const string targetPath = "Text";
const string sourcePath = "SourceText";
const string binding = "Text $context.SourceText";
var target = new object();
IBindingParser bindingParser = CreateBindingParser();
var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, target, null).Single());
IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
path.Path.ShouldEqual(targetPath);
var sources = context.GetData(BindingBuilderConstants.Sources);
IBindingSource source = sources.Single().Invoke(context);
BindingSourceShouldBeValid(source, AttachedMemberConstants.DataContext + "." + sourcePath, target);
}
示例8: Handle
public void Handle(XmlModule module, XElement element)
{
XAttribute serviceAttribute = element.RequiredAttribute("service");
Type service = GetTypeFromAttributeValue(serviceAttribute);
var binding = new Binding(service);
var builder = new BindingBuilder<object>(binding, _kernel);
module.AddBinding(binding);
if (!HandleTarget(element, builder))
throw new ConfigurationErrorsException("The 'bind' element does not define either a 'to' or 'toProvider' attribute.");
ReadName(element, builder);
ReadMetadata(element, builder);
ReadScope(element, builder);
}
示例9: ParserShouldUseTargetBindingContextForSource
public void ParserShouldUseTargetBindingContextForSource()
{
const string targetPath = "Text";
const string sourcePath = "IntProperty";
const string binding = "Text IntProperty";
var target = new object();
IBindingParser bindingParser = CreateBindingParser();
var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, target, null).Single());
IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
path.Path.ShouldEqual(targetPath);
var sources = context.GetData(BindingBuilderConstants.Sources);
IBindingSource source = sources.Single().Invoke(context);
BindingSourceShouldBeValidDataContext(target, source, sourcePath);
var sourceObj = new BindingSourceModel();
BindingServiceProvider.ContextManager.GetBindingContext(target).Value = sourceObj;
BindingSourceShouldBeValidDataContext(target, source, sourcePath);
}
示例10: BuilderShouldUseElementSource2
public void BuilderShouldUseElementSource2()
{
const string name = "name";
var builder = new BindingBuilder();
var targetObj = new BindingSourceModel { ObjectProperty = "test" };
var relativeObj = new BindingSourceModel();
bool isInvoked = false;
IEventListener eventListener = null;
var memberMock = new BindingMemberInfoMock
{
TryObserveMember = (o, listener) =>
{
eventListener = listener;
return null;
}
};
var treeManagerMock = new VisualTreeManagerMock
{
FindByName = (o, s) =>
{
o.ShouldEqual(targetObj);
s.ShouldEqual(name);
isInvoked = true;
return relativeObj;
},
GetRootMember = type => memberMock
};
BindingServiceProvider.VisualTreeManager = treeManagerMock;
builder.Bind(targetObj, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.Element<BindingSourceModel>(name).ObjectProperty);
var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
builder.GetData(BindingBuilderConstants.MultiExpression).ShouldBeNull();
source.Path.Path.ShouldEqual(GetMemberPath(targetObj, model => model.ObjectProperty));
source.GetSource(true).ShouldEqual(relativeObj);
var pathMembers = source.GetPathMembers(true);
pathMembers.LastMember.GetValue(pathMembers.PenultimateValue, null).ShouldEqual(relativeObj.ObjectProperty);
isInvoked.ShouldBeTrue();
isInvoked = false;
eventListener.ShouldNotBeNull();
eventListener.Handle(this, EventArgs.Empty);
isInvoked.ShouldBeTrue();
}
示例11: BuilderShouldUseTargetNullValue
public void BuilderShouldUseTargetNullValue()
{
var nullValue = new object();
var builder = new BindingBuilder();
builder.Bind(new object(), "test").To("test").WithTargetNullValue(nullValue);
builder.GetData(BindingBuilderConstants.TargetNullValue).ShouldEqual(nullValue);
}
示例12: 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);
}
示例13: 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();
}
示例14: 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);
}
示例15: BuilderShouldUseResource2
public void BuilderShouldUseResource2()
{
const string key = "key";
var builder = new BindingBuilder();
var sourceModel = new BindingSourceModel { ObjectProperty = "test" };
BindingServiceProvider.ResourceResolver.AddObject(key, sourceModel);
builder.Bind(sourceModel, "empty").To<BindingSourceModel>(() => model => BindingSyntaxEx.Self<BindingSourceModel>().ObjectProperty);
var source = builder.GetData(BindingBuilderConstants.Sources).Single().Invoke(builder);
builder.GetData(BindingBuilderConstants.MultiExpression).ShouldBeNull();
source.Path.Path.ShouldEqual(GetMemberPath(sourceModel, model => model.ObjectProperty));
source.GetSource(true).ShouldEqual(sourceModel);
var pathMembers = source.GetPathMembers(true);
pathMembers.LastMember.GetValue(pathMembers.PenultimateValue, null).ShouldEqual(sourceModel.ObjectProperty);
}