This commit is contained in:
José Manuel Nieto Sánchez 2016-01-02 23:05:47 +01:00
Родитель 4a1edb2774
Коммит 9895ee5f13
3 изменённых файлов: 11 добавлений и 11 удалений

Просмотреть файл

@ -6,17 +6,15 @@
public class MarkupExtensionNodeToXamlNodesConverter public class MarkupExtensionNodeToXamlNodesConverter
{ {
private readonly IWiringContext wiringContext; public MarkupExtensionNodeToXamlNodesConverter(ITypeContext typeContext)
public MarkupExtensionNodeToXamlNodesConverter(IWiringContext wiringContext)
{ {
this.wiringContext = wiringContext; TypeContext = typeContext;
} }
public IEnumerable<XamlInstruction> ParseMarkupExtensionNode(MarkupExtensionNode tree) public IEnumerable<XamlInstruction> ParseMarkupExtensionNode(MarkupExtensionNode tree)
{ {
var identifierNode = tree.Identifier; var identifierNode = tree.Identifier;
var xamlType = wiringContext.TypeContext.GetByPrefix(identifierNode.Prefix, identifierNode.TypeName); var xamlType = TypeContext.GetByPrefix(identifierNode.Prefix, identifierNode.TypeName);
yield return Inject.StartOfObject(xamlType); yield return Inject.StartOfObject(xamlType);
foreach (var instruction in ParseArguments(tree.Options.OfType<PositionalOption>())) yield return instruction; foreach (var instruction in ParseArguments(tree.Options.OfType<PositionalOption>())) yield return instruction;
@ -25,6 +23,8 @@
yield return Inject.EndOfObject(); yield return Inject.EndOfObject();
} }
private ITypeContext TypeContext { get; }
private static IEnumerable<XamlInstruction> ParseArguments(IEnumerable<PositionalOption> options) private static IEnumerable<XamlInstruction> ParseArguments(IEnumerable<PositionalOption> options)
{ {
var positionalOptions = options.ToList(); var positionalOptions = options.ToList();

Просмотреть файл

@ -303,7 +303,7 @@
private IEnumerable<XamlInstruction> ParseMarkupExtension(string valueOfMember) private IEnumerable<XamlInstruction> ParseMarkupExtension(string valueOfMember)
{ {
var tree = MarkupExtensionParser.MarkupExtension.Parse(valueOfMember); var tree = MarkupExtensionParser.MarkupExtension.Parse(valueOfMember);
var markupExtensionConverter = new MarkupExtensionNodeToXamlNodesConverter(wiringContext); var markupExtensionConverter = new MarkupExtensionNodeToXamlNodesConverter(wiringContext.TypeContext);
return markupExtensionConverter.ParseMarkupExtensionNode(tree); return markupExtensionConverter.ParseMarkupExtensionNode(tree);
} }

Просмотреть файл

@ -17,7 +17,7 @@
public void NameOnly() public void NameOnly()
{ {
var tree = new MarkupExtensionNode(new IdentifierNode("DummyExtension")); var tree = new MarkupExtensionNode(new IdentifierNode("DummyExtension"));
var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext); var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext.TypeContext);
var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList(); var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList();
var expectedInstructions = new List<XamlInstruction> var expectedInstructions = new List<XamlInstruction>
{ {
@ -32,7 +32,7 @@
public void NameAndAttribute() public void NameAndAttribute()
{ {
var tree = new MarkupExtensionNode(new IdentifierNode("DummyExtension"), new OptionsCollection {new PropertyOption("Property", new StringNode("Value"))}); var tree = new MarkupExtensionNode(new IdentifierNode("DummyExtension"), new OptionsCollection {new PropertyOption("Property", new StringNode("Value"))});
var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext); var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext.TypeContext);
var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList(); var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList();
var expectedInstructions = new List<XamlInstruction> var expectedInstructions = new List<XamlInstruction>
@ -55,7 +55,7 @@
new PropertyOption("Property", new StringNode("Value")), new PropertyOption("Property", new StringNode("Value")),
new PropertyOption("AnotherProperty", new StringNode("AnotherValue")), new PropertyOption("AnotherProperty", new StringNode("AnotherValue")),
}); });
var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext); var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext.TypeContext);
var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList(); var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList();
var expectedInstructions = new List<XamlInstruction> var expectedInstructions = new List<XamlInstruction>
@ -80,7 +80,7 @@
{ {
new PositionalOption("Option") new PositionalOption("Option")
}); });
var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext); var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext.TypeContext);
var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList(); var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList();
var expectedInstructions = new Collection<XamlInstruction> var expectedInstructions = new Collection<XamlInstruction>
@ -99,7 +99,7 @@
public void ComposedExtensionTemplateBindingWithConverter() public void ComposedExtensionTemplateBindingWithConverter()
{ {
var tree = MarkupExtensionNodeResources.ComposedExtensionTemplateBindingWithConverter(); var tree = MarkupExtensionNodeResources.ComposedExtensionTemplateBindingWithConverter();
var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext); var sut = new MarkupExtensionNodeToXamlNodesConverter(WiringContext.TypeContext);
var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList(); var actualNodes = sut.ParseMarkupExtensionNode(tree).ToList();
var expectedInstructions = new Collection<XamlInstruction> var expectedInstructions = new Collection<XamlInstruction>