private static XamlNamespaceRegistry CreateXamlNamespaceRegistry() { var xamlNamespaceRegistry = new XamlNamespaceRegistry(); var forcedAssemblies = new[] { typeof(Control), typeof(Style) }.Select(t => t.GetTypeInfo().Assembly); foreach (var nsa in forcedAssemblies .Concat(PerspexLocator.Current.GetService <IPclPlatformWrapper>().GetLoadedAssemblies()) .Distinct() .SelectMany(asm => asm.GetCustomAttributes <XmlnsDefinitionAttribute>().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); }
public void ParentPrefixesAreAvailableInChild() { var type = typeof(TextBlock); var assembly = type.GetTypeInfo().Assembly; var xamlNamespaces = XamlNamespace.Map("root").With(Route.Assembly(assembly).WithNamespaces(type.Namespace)); var prefixAnnotator = new PrefixAnnotator(); var sut = new PrefixedTypeResolver(prefixAnnotator, new TypeDirectory(new[] { xamlNamespaces })); var childNode = new ConstructionNode(typeof(TextBlock)); var root = new ConstructionNode(typeof(Window)) { Assignments = new List <MemberAssignment>() { new MemberAssignment() { Member = Member.FromStandard <Window>(window => window.Content), Children = new[] { childNode, } } }, }; prefixAnnotator.Annotate(root, new List <PrefixDeclaration>() { new PrefixDeclaration(string.Empty, "root") }); sut.Root = root; var buttonType = sut.GetTypeByPrefix(childNode, "Button"); Assert.Equal(typeof(Button), buttonType); }
private ITypeDirectory CreateSut() { var type = typeof(TextBlock); var assembly = type.GetTypeInfo().Assembly; var xamlNamespaces = XamlNamespace.Map("root").With(Route.Assembly(assembly).WithNamespaces(type.Namespace)); return(new TypeDirectory(new[] { xamlNamespaces })); }
private ITypeDirectory GetTypeDirectory() { var configuredAssemblyWithNamespaces = Route .Assembly(typeof(Window).Assembly) .WithNamespaces("System.Windows", "System.Windows.Controls"); var xamlNamespace = XamlNamespace .Map("root") .With(configuredAssemblyWithNamespaces); return(new TypeDirectory(new[] { xamlNamespace })); }
public void Initialize() { type = typeof(DummyClass); registry = new XamlNamespaceRegistry(); registry.RegisterPrefix(new PrefixRegistration("my", "target")); clrNamespace = $"clr-namespace:{type.Namespace};Assembly={type.GetTypeInfo().Assembly}"; registry.RegisterPrefix(new PrefixRegistration("clr", clrNamespace)); registry.AddNamespace( XamlNamespace.Map("target") .With(new[] { Route.Assembly(type.Assembly).WithNamespaces(new[] { type.Namespace }) })); }
private static TypeDirectory GetTypeDirectory() { var type = typeof(TextBlock); var typeAnother = typeof(CustomControl); var assembly = type.GetTypeInfo().Assembly; var nsAnother = XamlNamespace.Map("another").With(Route.Assembly(assembly).WithNamespaces(typeAnother.Namespace)); var newTypeDirectory = new TypeDirectory(new[] { nsAnother }); return(newTypeDirectory); }
public XamlTypeRepositoryTests() { nsRegistryMock = new Mock <IXamlNamespaceRegistry>(); var type = typeof(DummyClass); var fullyConfiguredMapping = XamlNamespace .Map("root") .With(new[] { Route.Assembly(type.Assembly).WithNamespaces(new[] { type.Namespace }) }); nsRegistryMock.Setup(registry => registry.GetNamespace("root")) .Returns(fullyConfiguredMapping); nsRegistryMock.Setup(registry => registry.GetNamespace("clr-namespace:DummyNamespace;Assembly=DummyAssembly")) .Returns(new ClrNamespace(type.Assembly, type.Namespace)); }
private ITypeDirectory RegisterTypeLocation() { var type = typeof(Page); var ass = type.GetTypeInfo().Assembly; var xamlNamespace = XamlNamespace .Map("root") .With( Route .Assembly(ass) .WithNamespaces(type.Namespace), Route .Assembly(typeof(OmniDataTemplate).GetTypeInfo().Assembly) .WithNamespaces(typeof(OmniDataTemplate).Namespace)); return(new TypeDirectory(new[] { xamlNamespace })); }
private IEnumerable <XamlNamespace> GetNamespaces(IEnumerable <Assembly> assemblies) { var routes = from a in assemblies let attributes = a.GetCustomAttributes <Tizen.NUI.XmlnsDefinitionAttribute>() from byNamespace in attributes.GroupBy(arg => arg.XmlNamespace) let name = byNamespace.Key let clrNamespaces = byNamespace.Select(arg => arg.ClrNamespace) let configuredAssemblyWithNamespaces = Route.Assembly(a).WithNamespaces(clrNamespaces.ToArray()) select new { Ns = name, configuredAssemblyWithNamespaces }; var nss = from route in routes group route by route.Ns into g let ns = g.Select(arg => arg.configuredAssemblyWithNamespaces).ToArray() select XamlNamespace.Map(g.Key).With(ns); return(nss); }
private static XamlNamespaceRegistry CreateXamlNamespaceRegistry() { var xamlNamespaceRegistry = new XamlNamespaceRegistry(); var rootType = typeof(DummyClass); var anotherType = typeof(Foreigner); var definitionForRoot = XamlNamespace .Map("root") .With( new[] { Route.Assembly(rootType.GetTypeInfo().Assembly) .WithNamespaces( new[] { rootType.Namespace, typeof(Window).Namespace, }) }); var definitionForAnother = XamlNamespace .Map("another") .With( new[] { Route.Assembly(anotherType.GetTypeInfo().Assembly) .WithNamespaces(new[] { anotherType.Namespace }) }); foreach (var ns in new List <XamlNamespace> { definitionForRoot, definitionForAnother }) { xamlNamespaceRegistry.AddNamespace(ns); } xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration("", "root")); xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration("x", "another")); return(xamlNamespaceRegistry); }
protected static ParseResult ParseResult(string xaml) { var ass = Assembly.Load(new AssemblyName("OmniXaml.Tests")); var namespaces = new[] { XamlNamespace.Map("root").With(Route.Assembly(ass).WithNamespaces("OmniXaml.Tests.Model")), XamlNamespace.Map("custom").With(Route.Assembly(ass).WithNamespaces("OmniXaml.Tests.Model.Custom")), }; var directory = new TypeDirectory(namespaces); var resolver = new XmlTypeXmlTypeResolver(directory); var sut = new XamlToTreeParser(new AttributeBasedMetadataProvider(), new[] { new InlineParser(resolver) }, resolver); var prefixAnnotator = new PrefixAnnotator(); var tree = sut.Parse(xaml, prefixAnnotator); return(tree); }
private static XamlNamespaceRegistry CreateXamlNamespaceRegistry() { 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 <XamlNamespace> { definitionForRoot }) { xamlNamespaceRegistry.AddNamespace(ns); } xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration(string.Empty, PerspexNs)); return(xamlNamespaceRegistry); }
private static NamespaceRegistry CreateXamlNamespaceRegistry() { var xamlNamespaceRegistry = new NamespaceRegistry(); var windowType = typeof(Window); var textBlockType = typeof(TextBlock); var toggleButtonType = typeof(ToggleButton); var rotateTransformType = typeof(RotateTransform); var bindingType = typeof(BindingExtension); var rootNs = XamlNamespace.Map(WpfRootNs) .With( new[] { Route.Assembly(bindingType.Assembly).WithNamespaces( new[] { bindingType.Namespace }), Route.Assembly(rotateTransformType.Assembly).WithNamespaces( new[] { rotateTransformType.Namespace }), Route.Assembly(bindingType.Assembly).WithNamespaces( new[] { bindingType.Namespace }), Route.Assembly(windowType.Assembly).WithNamespaces( new[] { windowType.Namespace, textBlockType.Namespace, toggleButtonType.Namespace }) }); foreach (var ns in new List <XamlNamespace> { rootNs }) { xamlNamespaceRegistry.AddNamespace(ns); } xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration("", WpfRootNs)); return(xamlNamespaceRegistry); }