From bec230211a0f08038bcca73d5661c80dd4a9e51a Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 15 Sep 2015 22:45:27 +0300 Subject: [PATCH 1/2] Now resolving xml namespaces via attributes --- Perspex.sln | 1 + .../XamlTestApplication/Views/MainWindow.xaml | 112 +----------------- src/Gtk/Perspex.Gtk/GtkPlatform.cs | 1 + src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj | 3 + .../Context/PerspexWiringContext.cs | 53 ++++----- .../Properties/AssemblyInfo.cs | 3 + .../Metadata/XmlnsDefinitionAttribute.cs | 21 ++++ src/Perspex.Base/Perspex.Base.csproj | 2 + .../Platform/IPclPlatformWrapper.cs | 14 +++ .../Properties/AssemblyInfo.cs | 6 +- .../Properties/AssemblyInfo.cs | 2 + src/Shared/PclPlatformWrapper.cs | Bin 0 -> 806 bytes .../Perspex.Win32/Perspex.Win32.csproj | 3 + src/Windows/Perspex.Win32/Win32Platform.cs | 1 + 14 files changed, 85 insertions(+), 137 deletions(-) create mode 100644 src/Perspex.Base/Metadata/XmlnsDefinitionAttribute.cs create mode 100644 src/Perspex.Base/Platform/IPclPlatformWrapper.cs create mode 100644 src/Shared/PclPlatformWrapper.cs diff --git a/Perspex.sln b/Perspex.sln index 54c810f636..20a7fa624e 100644 --- a/Perspex.sln +++ b/Perspex.sln @@ -79,6 +79,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{9B9E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{A689DEF5-D50F-4975-8B72-124C9EB54066}" ProjectSection(SolutionItems) = preProject + src\Shared\PclPlatformWrapper.cs = src\Shared\PclPlatformWrapper.cs src\Shared\SharedAssemblyInfo.cs = src\Shared\SharedAssemblyInfo.cs EndProjectSection EndProject diff --git a/samples/XamlTestApplication/Views/MainWindow.xaml b/samples/XamlTestApplication/Views/MainWindow.xaml index 96f4db9653..78d30bda9f 100644 --- a/samples/XamlTestApplication/Views/MainWindow.xaml +++ b/samples/XamlTestApplication/Views/MainWindow.xaml @@ -2,111 +2,9 @@ xmlns="https://github.com/perspex" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Perspex Test Application" Height="350" Width="525"> - - - - - - - - - + + + \ No newline at end of file diff --git a/src/Gtk/Perspex.Gtk/GtkPlatform.cs b/src/Gtk/Perspex.Gtk/GtkPlatform.cs index d02e112845..2881bd292f 100644 --- a/src/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/src/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -28,6 +28,7 @@ namespace Perspex.Gtk public static void Initialize() { var locator = Locator.CurrentMutable; + locator.Register(() => new PclPlatformWrapper(), typeof(IPclPlatformWrapper)); locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => new ClipboardImpl(), typeof(IClipboard)); diff --git a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index 563d87b2a3..95d3c8c5c5 100644 --- a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -58,6 +58,9 @@ + + PclPlatformWrapper.cs + diff --git a/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs b/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs index 45894a58eb..cf16bcb8f7 100644 --- a/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs +++ b/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Reflection; using Glass; using OmniXaml; @@ -16,6 +17,10 @@ using Perspex.Markup.Xaml.DataBinding; using Perspex.Markup.Xaml.MarkupExtensions; using Perspex.Media; using Perspex.Media.Imaging; +using Perspex.Metadata; +using Perspex.Platform; +using Perspex.Styling; +using Splat; namespace Perspex.Markup.Xaml.Context { @@ -39,37 +44,27 @@ namespace Perspex.Markup.Xaml.Context { var xamlNamespaceRegistry = new XamlNamespaceRegistry(); - var rootType = typeof(Control); - var bindingType = typeof(BindingExtension); - var templateType = typeof(XamlDataTemplate); - - var definitionForRoot = XamlNamespace - .Map(PerspexNs) - .With( - new[] - { - Route.Assembly(rootType.GetTypeInfo().Assembly).WithNamespaces( - new[] - { - rootType.Namespace - }), - Route.Assembly(bindingType.GetTypeInfo().Assembly).WithNamespaces( - new[] - { - bindingType.Namespace, - }), - Route.Assembly(templateType.GetTypeInfo().Assembly).WithNamespaces( - new[] - { - templateType.Namespace, - }) - }); - - foreach (var ns in new List { definitionForRoot }) + var forcedAssemblies = new[] { - xamlNamespaceRegistry.AddNamespace(ns); + typeof (Control), + typeof(Style) + }.Select(t => t.GetTypeInfo().Assembly); + + foreach (var nsa in + forcedAssemblies + .Concat(Locator.Current.GetService().GetLoadedAssemblies()) + .Distinct() + .SelectMany(asm + => asm.GetCustomAttributes().Select(attr => new {asm, attr})) + .GroupBy(entry => entry.attr.XmlNamespace)) + { + var def = XamlNamespace.Map(nsa.Key) + .With(nsa.GroupBy(x => x.asm).Select( + a => Route.Assembly(a.Key) + .WithNamespaces(a.Select(entry => entry.attr.ClrNamespace).ToList()) + )); + xamlNamespaceRegistry.AddNamespace(def); } - xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration(string.Empty, PerspexNs)); return xamlNamespaceRegistry; diff --git a/src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs b/src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs index eea5e0803d..07a61a6798 100644 --- a/src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs +++ b/src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs @@ -2,5 +2,8 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System.Reflection; +using Perspex.Metadata; [assembly: AssemblyTitle("Perspex.Markup.Xaml")] +[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup.Xaml.MarkupExtensions")] +[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup.Xaml.Templates")] \ No newline at end of file diff --git a/src/Perspex.Base/Metadata/XmlnsDefinitionAttribute.cs b/src/Perspex.Base/Metadata/XmlnsDefinitionAttribute.cs new file mode 100644 index 0000000000..63371bf80f --- /dev/null +++ b/src/Perspex.Base/Metadata/XmlnsDefinitionAttribute.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Perspex.Metadata +{ + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public class XmlnsDefinitionAttribute : Attribute + { + public string XmlNamespace { get; set; } + public string ClrNamespace { get; set; } + + public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) + { + XmlNamespace = xmlNamespace; + ClrNamespace = clrNamespace; + } + } +} diff --git a/src/Perspex.Base/Perspex.Base.csproj b/src/Perspex.Base/Perspex.Base.csproj index 8370b131f1..0ab51860f1 100644 --- a/src/Perspex.Base/Perspex.Base.csproj +++ b/src/Perspex.Base/Perspex.Base.csproj @@ -46,8 +46,10 @@ + + diff --git a/src/Perspex.Base/Platform/IPclPlatformWrapper.cs b/src/Perspex.Base/Platform/IPclPlatformWrapper.cs new file mode 100644 index 0000000000..c57b87a738 --- /dev/null +++ b/src/Perspex.Base/Platform/IPclPlatformWrapper.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Perspex.Platform +{ + public interface IPclPlatformWrapper + { + Assembly[] GetLoadedAssemblies(); + } +} diff --git a/src/Perspex.Controls/Properties/AssemblyInfo.cs b/src/Perspex.Controls/Properties/AssemblyInfo.cs index 479c2fc91b..4cda6c4aa5 100644 --- a/src/Perspex.Controls/Properties/AssemblyInfo.cs +++ b/src/Perspex.Controls/Properties/AssemblyInfo.cs @@ -3,6 +3,10 @@ using System.Reflection; using System.Runtime.CompilerServices; +using Perspex.Metadata; [assembly: AssemblyTitle("Perspex.Controls")] -[assembly: InternalsVisibleTo("Perspex.Controls.UnitTests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Perspex.Controls.UnitTests")] + +[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Controls")] +[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Controls.Primitives")] \ No newline at end of file diff --git a/src/Perspex.Styling/Properties/AssemblyInfo.cs b/src/Perspex.Styling/Properties/AssemblyInfo.cs index 3dbe71ef35..f06c17710e 100644 --- a/src/Perspex.Styling/Properties/AssemblyInfo.cs +++ b/src/Perspex.Styling/Properties/AssemblyInfo.cs @@ -2,5 +2,7 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System.Reflection; +using Perspex.Metadata; [assembly: AssemblyTitle("Perspex.Styling")] +[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Styling")] \ No newline at end of file diff --git a/src/Shared/PclPlatformWrapper.cs b/src/Shared/PclPlatformWrapper.cs new file mode 100644 index 0000000000000000000000000000000000000000..9057a8085b2359748b34cc3ad0663ae476b75ecc GIT binary patch literal 806 zcma))K}*9x6olt2_#gJDm-MbEh=LRp#0nn7Lru~eY15K4ViEtk`pu@2wpb`jv)#Az zX6EgCKi@s|6m+SX=31&!p|M`IAay1+iJ|S|U2`j9z z)bW&)<=l6^8OTE&plaP4^irZ_L}Wx7{$~*#U~QFe)yGAEdmU}X0Z4o6Zp@Zw3P;cg z{3PBNuy%ZNymZd(cgAwfBlarp4VkW`V|EPz#&U(4YDi8&M!BlVbv0CC%oyx|7p=kM z_&JSL@48KN4{8+M`ZZhDeR68_8$7%2`X80et|fGF5`DLo{`s==G~U#(xYs^yV;|8O z(tl5YU+IKje=n^0KjRAoa=hlaenG<>_2gLB@8sB0PkJVLO=Q80%uw}AWLvm`Sk0Vz kO3!p2dF<|r40p$UNSJNEPX)GwZS$^G*i`RW+xP#{FKM2P{{R30 literal 0 HcmV?d00001 diff --git a/src/Windows/Perspex.Win32/Perspex.Win32.csproj b/src/Windows/Perspex.Win32/Perspex.Win32.csproj index a55bba662b..68093baf10 100644 --- a/src/Windows/Perspex.Win32/Perspex.Win32.csproj +++ b/src/Windows/Perspex.Win32/Perspex.Win32.csproj @@ -62,6 +62,9 @@ + + PclPlatformWrapper.cs + Properties\SharedAssemblyInfo.cs diff --git a/src/Windows/Perspex.Win32/Win32Platform.cs b/src/Windows/Perspex.Win32/Win32Platform.cs index da4be6b6a6..4cfe797450 100644 --- a/src/Windows/Perspex.Win32/Win32Platform.cs +++ b/src/Windows/Perspex.Win32/Win32Platform.cs @@ -40,6 +40,7 @@ namespace Perspex.Win32 private static void InitializeInternal() { var locator = Locator.CurrentMutable; + locator.Register(()=>new PclPlatformWrapper(), typeof(IPclPlatformWrapper)); locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => new ClipboardImpl(), typeof(IClipboard)); locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); From 7df76d17ba11aa535a99b6c6b36a88ab9aa534e9 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 15 Sep 2015 23:00:01 +0300 Subject: [PATCH 2/2] I accidentally the whole MainWindow.cs --- .../XamlTestApplication/Views/MainWindow.xaml | 112 +++++++++++++++++- 1 file changed, 107 insertions(+), 5 deletions(-) diff --git a/samples/XamlTestApplication/Views/MainWindow.xaml b/samples/XamlTestApplication/Views/MainWindow.xaml index 78d30bda9f..96f4db9653 100644 --- a/samples/XamlTestApplication/Views/MainWindow.xaml +++ b/samples/XamlTestApplication/Views/MainWindow.xaml @@ -2,9 +2,111 @@ xmlns="https://github.com/perspex" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Perspex Test Application" Height="350" Width="525"> - - - + + + + + + + + + \ No newline at end of file