This commit is contained in:
José Manuel Nieto Sánchez 2015-09-02 11:40:39 +02:00
Родитель 46cdd21a22
Коммит 58f0692fad
9 изменённых файлов: 47 добавлений и 36 удалений

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

@ -0,0 +1,12 @@
namespace OmniXaml
{
public class NamespacePrefix
{
public NamespacePrefix(string prefix)
{
Prefix = prefix;
}
public string Prefix { get; set; }
}
}

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

@ -39,6 +39,7 @@
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="INameScope.cs" />
<Compile Include="NamespacePrefix.cs" />
<Compile Include="ObjectAssembler\CurrentLevelWrapper.cs" />
<Compile Include="ObjectAssembler\InstanceProperties.cs" />
<Compile Include="ObjectAssembler\NullLevel.cs" />

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

@ -146,7 +146,7 @@
}
var namespaceDeclaration = new NamespaceDeclaration(rawAttribute.Locator.Namespace, rawAttribute.Locator.Prefix);
return instructionBuilder.Attribute(member, rawAttribute.Value, namespaceDeclaration);
return instructionBuilder.Attribute(member, rawAttribute.Value, namespaceDeclaration.Prefix);
}
private AttributeFeed GetAttributes()
@ -205,17 +205,11 @@
{
if (directive.Locator.PropertyName == "Key")
{
return instructionBuilder.Attribute(
CoreTypes.Key,
directive.Value,
new NamespaceDeclaration("http://schemas.microsoft.com/winfx/2006/xaml", "x"));
return instructionBuilder.Attribute(CoreTypes.Key, directive.Value, "x");
}
if (directive.Locator.PropertyName == "Name")
{
return instructionBuilder.Attribute(
CoreTypes.Name,
directive.Value,
new NamespaceDeclaration(null, "x"));
return instructionBuilder.Attribute(CoreTypes.Name, directive.Value,"x");
}
throw new XamlParseException($"Cannot handle the directive {directive.Locator.PropertyName}");

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

@ -163,26 +163,26 @@
return new ProtoXamlInstruction { Namespace = null, NodeType = NodeType.Text, XamlType = null, Text = text };
}
public ProtoXamlInstruction Attribute(XamlMemberBase member, string value, NamespaceDeclaration namespaceDeclaration)
public ProtoXamlInstruction Attribute(XamlMemberBase member, string value, string prefix)
{
return new ProtoXamlInstruction
{
PropertyAttribute = member,
NodeType = NodeType.Attribute,
PropertyAttributeText = value,
Prefix = namespaceDeclaration.Prefix,
Prefix = prefix,
};
}
public ProtoXamlInstruction Attribute<T>(Expression<Func<T, object>> selector, string value, NamespaceDeclaration namespaceDeclaration)
public ProtoXamlInstruction Attribute<T>(Expression<Func<T, object>> selector, string value, string prefix)
{
var xamlMember = typeContext.GetXamlType(typeof(T)).GetMember(selector.GetFullPropertyName());
return Attribute(xamlMember, value, namespaceDeclaration);
return Attribute(xamlMember, value, prefix);
}
public ProtoXamlInstruction Key(string value)
{
return Attribute(CoreTypes.Key, value, new NamespaceDeclaration("http://schemas.microsoft.com/winfx/2006/xaml", "x"));
return Attribute(CoreTypes.Key, value, "x");
}
}
}

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

@ -4,6 +4,7 @@
public static class CoreTypes
{
public static string SpecialNamespace = "http://schemas.microsoft.com/winfx/2006/xaml";
private static readonly XamlDirective ItemsField = new XamlDirective("_Items", XamlType.CreateForBuiltInType(typeof(List<object>)));
private static readonly XamlDirective InitializationField = new XamlDirective("_Initialization");
private static readonly XamlDirective MarkupExtensionArgumentsField = new XamlDirective("_MarkupExtensionParameters");

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

@ -2,6 +2,7 @@ namespace OmniXaml.Tests.Common
{
using System.Collections.Generic;
using System.Reflection;
using Typing;
public class GivenAWiringContext
{
@ -15,6 +16,6 @@ namespace OmniXaml.Tests.Common
protected IWiringContext WiringContext => new DummyWiringContext(new TypeFactory(), assemblies);
public NamespaceDeclaration RootNs { get; } = new NamespaceDeclaration("root", string.Empty);
public NamespaceDeclaration AnotherNs { get; } = new NamespaceDeclaration("another", "a");
public NamespaceDeclaration SpecialNs { get; } = new NamespaceDeclaration("http://schemas.microsoft.com/winfx/2006/xaml", "x");
public NamespaceDeclaration SpecialNs { get; } = new NamespaceDeclaration(CoreTypes.SpecialNamespace, "x");
}
}

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

@ -24,7 +24,7 @@
{
P.NamespacePrefixDeclaration(RootNs),
P.EmptyElement(typeof (DummyClass), RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "{Dummy}", RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "{Dummy}", RootNs.Prefix),
};
var expectedInstructions = new List<XamlInstruction>
@ -50,7 +50,7 @@
{
P.NamespacePrefixDeclaration(RootNs),
P.EmptyElement(typeof (DummyClass), RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "{Dummy Option}", RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "{Dummy Option}", RootNs.Prefix),
};
var expectedInstructions = new List<XamlInstruction>

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

@ -5,6 +5,7 @@ namespace OmniXaml.Tests.Resources
using Classes;
using Classes.WpfLikeModel;
using Common;
using Typing;
internal class ProtoInstructionResources
{
@ -29,22 +30,22 @@ namespace OmniXaml.Tests.Resources
P.NamespacePrefixDeclaration(RootNs),
P.NonEmptyElement(typeof (DummyClass), RootNs),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Main1", RootNs),
P.Attribute<Item>(d => d.Title, "Main1", RootNs.Prefix),
P.Text(),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Main2", RootNs),
P.Attribute<Item>(d => d.Title, "Main2", RootNs.Prefix),
P.Text(),
P.NonEmptyPropertyElement<DummyClass>(d => d.Child, RootNs),
P.NonEmptyElement(typeof (ChildClass), RootNs),
P.NonEmptyElement(typeof (Item), RootNs),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Item1", RootNs),
P.Attribute<Item>(d => d.Title, "Item1", RootNs.Prefix),
P.Text(),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Item2", RootNs),
P.Attribute<Item>(d => d.Title, "Item2", RootNs.Prefix),
P.Text(),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Item3", RootNs),
P.Attribute<Item>(d => d.Title, "Item3", RootNs.Prefix),
P.Text(),
P.EndTag(),
P.Text(),
@ -70,10 +71,10 @@ namespace OmniXaml.Tests.Resources
P.NonEmptyElement(typeof (DummyClass), RootNs),
P.NonEmptyPropertyElement<DummyClass>(d => d.Items, RootNs),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Main1", RootNs),
P.Attribute<Item>(d => d.Title, "Main1", RootNs.Prefix),
P.Text(),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Main2", RootNs),
P.Attribute<Item>(d => d.Title, "Main2", RootNs.Prefix),
P.Text(),
P.EndTag(),
P.NonEmptyPropertyElement<DummyClass>(d => d.Child, RootNs),
@ -97,7 +98,7 @@ namespace OmniXaml.Tests.Resources
P.NonEmptyElement(typeof (ChildClass), RootNs),
P.NonEmptyElement(typeof (Item), RootNs),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Item1", RootNs),
P.Attribute<Item>(d => d.Title, "Item1", RootNs.Prefix),
P.Text(),
P.EndTag(),
P.EndTag(),
@ -117,7 +118,7 @@ namespace OmniXaml.Tests.Resources
P.NonEmptyElement(typeof (ChildClass), RootNs),
P.NonEmptyElement(typeof (Item), RootNs),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Item1", RootNs),
P.Attribute<Item>(d => d.Title, "Item1", RootNs.Prefix),
P.Text(),
P.EndTag(),
P.Text(),
@ -243,7 +244,7 @@ namespace OmniXaml.Tests.Resources
{
P.NamespacePrefixDeclaration(RootNs),
P.NonEmptyElement(typeof(DummyClass), RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "Property!", RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "Property!", RootNs.Prefix),
P.EndTag(),
};
}
@ -256,7 +257,7 @@ namespace OmniXaml.Tests.Resources
return new Collection<ProtoXamlInstruction>
{
P.NamespacePrefixDeclaration(RootNs),
P.NamespacePrefixDeclaration("x", "http://schemas.microsoft.com/winfx/2006/xaml"),
P.NamespacePrefixDeclaration("x", CoreTypes.SpecialNamespace),
P.NonEmptyElement(typeof(DummyClass), RootNs),
P.NonEmptyPropertyElement<DummyClass>(d => d.Resources, RootNs),
P.EmptyElement(typeof(ChildClass), RootNs),
@ -382,7 +383,7 @@ namespace OmniXaml.Tests.Resources
{
P.NamespacePrefixDeclaration(RootNs),
P.EmptyElement(typeof (DummyClass), RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "Property!", RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "Property!", RootNs.Prefix),
};
}
}
@ -395,8 +396,8 @@ namespace OmniXaml.Tests.Resources
{
P.NamespacePrefixDeclaration(RootNs),
P.EmptyElement(typeof (DummyClass), RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "Property!", RootNs),
P.Attribute<DummyClass>(d => d.AnotherProperty, "Another!", RootNs),
P.Attribute<DummyClass>(d => d.SampleProperty, "Property!", RootNs.Prefix),
P.Attribute<DummyClass>(d => d.AnotherProperty, "Another!", RootNs.Prefix),
};
}
}
@ -508,11 +509,11 @@ namespace OmniXaml.Tests.Resources
P.NonEmptyElement(typeof (DummyClass), RootNs),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Main1", RootNs),
P.Attribute<Item>(d => d.Title, "Main1", RootNs.Prefix),
P.Text(),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(d => d.Title, "Main2", RootNs),
P.Attribute<Item>(d => d.Title, "Main2", RootNs.Prefix),
P.Text(),
P.NonEmptyPropertyElement<DummyClass>(d => d.Child, RootNs),
@ -549,12 +550,12 @@ namespace OmniXaml.Tests.Resources
{
P.NamespacePrefixDeclaration(RootNs),
P.NonEmptyElement(typeof (DummyClass), RootNs),
P.Attribute<DummyClass>(@class => @class.SampleProperty, "Sample", RootNs),
P.Attribute<DummyClass>(@class => @class.SampleProperty, "Sample", RootNs.Prefix),
P.NonEmptyPropertyElement<DummyClass>(d => d.Child, RootNs),
P.NonEmptyElement(typeof (ChildClass), RootNs),
P.NonEmptyPropertyElement<ChildClass>(d => d.Content, RootNs),
P.EmptyElement(typeof (Item), RootNs),
P.Attribute<Item>(@class => @class.Text, "Value!", RootNs),
P.Attribute<Item>(@class => @class.Text, "Value!", RootNs.Prefix),
P.Text(),
P.EndTag(),
P.EndTag(),

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

@ -7,6 +7,7 @@ namespace OmniXaml.Tests.Resources
using Classes.Another;
using Classes.WpfLikeModel;
using Common;
using Typing;
public class XamlInstructionResources
{
@ -658,7 +659,7 @@ namespace OmniXaml.Tests.Resources
return new List<XamlInstruction>
{
X.NamespacePrefixDeclaration(RootNs),
X.NamespacePrefixDeclaration("http://schemas.microsoft.com/winfx/2006/xaml", "x"),
X.NamespacePrefixDeclaration(CoreTypes.SpecialNamespace, "x"),
X.StartObject<DummyClass>(),
X.StartMember<DummyClass>(d => d.Resources),
X.GetObject(),