Exemple #1
0
        //https://github.com/xamarin/Duplo/issues/1207#issuecomment-47159917
        public void xNameInCustomTypes()
        {
            var xaml = @"<ContentPage
    xmlns=""http://xamarin.com/schemas/2014/forms""
    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
    xmlns:local=""clr-namespace:CustomListViewSample;assembly=CustomListViewSample""
    xmlns:localusing=""using:CustomListViewSample""
    x:Class=""CustomListViewSample.TestPage"">
    <StackLayout 
        VerticalOptions=""CenterAndExpand""
        HorizontalOptions=""CenterAndExpand"">
        <Label Text=""Hello, Custom Renderer!"" />
        <local:CustomListView x:Name=""listView""
            WidthRequest=""960"" CornerRadius=""50"" OutlineColor=""Blue"" />
		<localusing:CustomListView x:Name=""listViewusing"" />
    </StackLayout>
</ContentPage>";

            var reader = new StringReader(xaml);

            var generator = new XamlGenerator();

            generator.ParseXaml(reader);

            Assert.AreEqual(2, generator.NamedFields.Count());
            Assert.AreEqual("listView", generator.NamedFields.ToArray()[0].Name);
            Assert.AreEqual("CustomListViewSample.CustomListView", generator.NamedFields.ToArray()[0].Type.BaseType);
            Assert.AreEqual("listViewusing", generator.NamedFields.ToArray()[1].Name);
            Assert.AreEqual("CustomListViewSample.CustomListView", generator.NamedFields.ToArray()[1].Type.BaseType);
        }
Exemple #2
0
        public void MulipleXTypeArgumentsMulitpleNamespacesOnRootElementWithWhitespace()
        {
            var xaml   = @"<ObservableWrapper 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" 
							x:TypeArguments=""nsone:IDummyInterface, nstwo:IDummyInterfaceTwo""
							xmlns:nsone=""clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests.Bugzilla24258.Interfaces""
							xmlns:nstwo=""clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests.Bugzilla24258.InterfacesTwo""

			/>"            ;
            var reader = new StringReader(xaml);

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(reader);

            Assert.AreEqual("FooBar", generator.RootType);
            Assert.AreEqual("Microsoft.Maui.Controls.ObservableWrapper`2", generator.BaseType.BaseType);
            Assert.AreEqual(2, generator.BaseType.TypeArguments.Count);
            Assert.AreEqual("Microsoft.Maui.Controls.Xaml.UnitTests.Bugzilla24258.Interfaces.IDummyInterface", generator.BaseType.TypeArguments[0].BaseType);
            Assert.AreEqual("Microsoft.Maui.Controls.Xaml.UnitTests.Bugzilla24258.InterfacesTwo.IDummyInterfaceTwo", generator.BaseType.TypeArguments[1].BaseType);
        }
Exemple #3
0
        public void MulipleXTypeArgumentsOnRootElementWithWhitespace()
        {
            var xaml   = @"<ObservableWrapper 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" 
							x:TypeArguments=""x:String, x:Int32""
			/>"            ;
            var reader = new StringReader(xaml);

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(reader);

            Assert.AreEqual("FooBar", generator.RootType);
            Assert.AreEqual("Microsoft.Maui.Controls.ObservableWrapper`2", generator.BaseType.BaseType);
            Assert.AreEqual(2, generator.BaseType.TypeArguments.Count);
            Assert.AreEqual("System.String", generator.BaseType.TypeArguments[0].BaseType);
            Assert.AreEqual("System.Int32", generator.BaseType.TypeArguments[1].BaseType);
        }
Exemple #4
0
        public void FieldModifier()
        {
            var xaml = @"
			<ContentPage xmlns=""http://xamarin.com/schemas/2014/forms""
			             xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
			             xmlns:local=""clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests""
			             x:Class=""Microsoft.Maui.Controls.Xaml.UnitTests.FieldModifier"">
				<StackLayout>
			        <Label x:Name=""privateLabel"" />
			        <Label x:Name=""internalLabel"" x:FieldModifier=""NotPublic"" />
			        <Label x:Name=""publicLabel"" x:FieldModifier=""Public"" />
				</StackLayout>
			</ContentPage>"            ;

            using (var reader = new StringReader(xaml))
            {
                var references = string.Join(";",
                                             IOPath.GetFullPath(
                                                 IOPath.Combine(
                                                     TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                             IOPath.GetFullPath(
                                                 IOPath.Combine(
                                                     TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                             );

                var generator = new XamlGenerator(null, null, null, null, null, null, references);
                generator.ParseXaml(reader);

                Assert.That(generator.NamedFields.First(cmf => cmf.Name == "privateLabel").Attributes, Is.EqualTo(MemberAttributes.Private));
                Assert.That(generator.NamedFields.First(cmf => cmf.Name == "internalLabel").Attributes, Is.EqualTo(MemberAttributes.Assembly));
                Assert.That(generator.NamedFields.First(cmf => cmf.Name == "publicLabel").Attributes, Is.EqualTo(MemberAttributes.Public));
            }
        }
Exemple #5
0
        //https://bugzilla.xamarin.com/show_bug.cgi?id=33256
        public void AlwaysUseGlobalReference()
        {
            var xaml = @"
			<ContentPage
				xmlns=""http://xamarin.com/schemas/2014/forms""
				xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
				x:Class=""FooBar"" >
				<Label x:Name=""label0""/>
			</ContentPage>"            ;

            using (var reader = new StringReader(xaml))
            {
                var references = string.Join(";",
                                             IOPath.GetFullPath(
                                                 IOPath.Combine(
                                                     TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                             IOPath.GetFullPath(
                                                 IOPath.Combine(
                                                     TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                             );

                var generator = new XamlGenerator(null, null, null, null, null, null, references);
                generator.ParseXaml(reader);

                Assert.IsTrue(generator.BaseType.Options.HasFlag(CodeTypeReferenceOptions.GlobalReference));
                Assert.IsTrue(generator.NamedFields.Select(cmf => cmf.Type).First().Options.HasFlag(CodeTypeReferenceOptions.GlobalReference));
            }
        }
Exemple #6
0
        public void xNameInDataTemplates()
        {
            var xaml   = @"<StackLayout 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" >
							<ListView>
								<ListView.ItemTemplate>
									<DataTemplate>
										<ViewCell>
											<Label x:Name=""notincluded""/>
										</ViewCell>
									</DataTemplate>
								</ListView.ItemTemplate>
							</ListView>
							<Label x:Name=""included""/>
						</StackLayout>"                        ;
            var reader = new StringReader(xaml);

            var generator = new XamlGenerator();

            generator.ParseXaml(reader);

            Assert.Contains("included", generator.NamedFields.Select(cmf => cmf.Name).ToList());
            Assert.False(generator.NamedFields.Select(cmf => cmf.Name).Contains("notincluded"));
            Assert.AreEqual(1, generator.NamedFields.Count());
        }
Exemple #7
0
        public void xNameInStyles()
        {
            var xaml   = @"<StackLayout 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" >
							<StackLayout.Resources>
								<ResourceDictionary>
									<Style TargetType=""Label"" >
										<Setter Property=""Text"">
											<Setter.Value>
												<Label x:Name=""notincluded"" />
											</Setter.Value>
										</Setter>
									</Style>
								</ResourceDictionary>
							</StackLayout.Resources>
						</StackLayout>"                        ;
            var reader = new StringReader(xaml);

            var generator = new XamlGenerator();

            generator.ParseXaml(reader);

            Assert.False(generator.NamedFields.Select(cmf => cmf.Name).Contains("notincluded"));
            Assert.AreEqual(0, generator.NamedFields.Count());
        }
Exemple #8
0
        public void xTypeArgumentsOnRootElement()
        {
            var xaml   = @"<Layout 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" 
							x:TypeArguments=""x:String""
			/>"            ;
            var reader = new StringReader(xaml);

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Xamarin.Forms.Controls.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Xamarin.Forms.Core.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(reader);

            Assert.AreEqual("FooBar", generator.RootType);
            Assert.AreEqual("Xamarin.Forms.Layout`1", generator.BaseType.BaseType);
            Assert.AreEqual(1, generator.BaseType.TypeArguments.Count);
            Assert.AreEqual("System.String", generator.BaseType.TypeArguments[0].BaseType);
        }
Exemple #9
0
        //https://github.com/xamarin/Microsoft.Maui.Controls/issues/2574
        public void xNameOnRoot()
        {
            var xaml = @"<ContentPage
		xmlns=""http://xamarin.com/schemas/2014/forms""
		xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
		x:Class=""Foo""
		x:Name=""bar"">
	</ContentPage>"    ;

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(new StringReader(xaml));

            Assert.AreEqual(1, generator.NamedFields.Count());
            Assert.AreEqual("bar", generator.NamedFields.First().Name);
            Assert.AreEqual("Microsoft.Maui.Controls.ContentPage", generator.NamedFields.First().Type.BaseType);
        }
Exemple #10
0
        public void LoadXaml2009()
        {
            var xaml = @"<View
					xmlns=""http://xamarin.com/schemas/2014/forms""
					xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
					x:Class=""Microsoft.Maui.Controls.Xaml.UnitTests.CustomView"" >
						<Label x:Name=""label0""/>
					</View>"                    ;

            var reader = new StringReader(xaml);

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(reader);
            Assert.NotNull(generator.RootType);
            Assert.NotNull(generator.RootClrNamespace);
            Assert.NotNull(generator.BaseType);
            Assert.NotNull(generator.NamedFields);

            Assert.AreEqual("CustomView", generator.RootType);
            Assert.AreEqual("Microsoft.Maui.Controls.Xaml.UnitTests", generator.RootClrNamespace);
            Assert.AreEqual("Microsoft.Maui.Controls.View", generator.BaseType.BaseType);
            Assert.AreEqual(1, generator.NamedFields.Count());
            Assert.AreEqual("label0", generator.NamedFields.First().Name);
            Assert.AreEqual("Microsoft.Maui.Controls.Label", generator.NamedFields.First().Type.BaseType);
        }
Exemple #11
0
        public void LoadXaml2009()
        {
            var xaml = @"<View
					xmlns=""http://xamarin.com/schemas/2014/forms""
					xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
					x:Class=""Xamarin.Forms.Xaml.UnitTests.CustomView"" >
						<Label x:Name=""label0""/>
					</View>"                    ;

            var reader = new StringReader(xaml);

            var generator = new XamlGenerator();

            generator.ParseXaml(reader);
            Assert.NotNull(generator.RootType);
            Assert.NotNull(generator.RootClrNamespace);
            Assert.NotNull(generator.BaseType);
            Assert.NotNull(generator.NamedFields);

            Assert.AreEqual("CustomView", generator.RootType);
            Assert.AreEqual("Xamarin.Forms.Xaml.UnitTests", generator.RootClrNamespace);
            Assert.AreEqual("Xamarin.Forms.View", generator.BaseType.BaseType);
            Assert.AreEqual(1, generator.NamedFields.Count());
            Assert.AreEqual("label0", generator.NamedFields.First().Name);
            Assert.AreEqual("Xamarin.Forms.Label", generator.NamedFields.First().Type.BaseType);
        }
Exemple #12
0
            public void TestXamlGenerator()
            {
                string xamlInputFile  = CreateXamlInputFile();
                string xamlOutputFile = IOPath.GetTempFileName();
                var    item           = new TaskItem(xamlInputFile);

                item.SetMetadata("TargetPath", xamlInputFile);

                string testAssemblyBinPath =
#if DEBUG
                    "Debug";
#else
                    "Release";
#endif

                var dir = IOPath.GetFullPath(
                    IOPath.Combine(
                        TestContext.CurrentContext.TestDirectory, "Xamarin.Forms.Controls.dll"));
                var xamlg = new XamlGTask()
                {
                    BuildEngine  = new DummyBuildEngine(),
                    AssemblyName = "test",
                    Language     = "C#",
                    XamlFiles    = new[] { item },
                    OutputFiles  = new[] { new TaskItem(xamlOutputFile) },
                    References   = dir
                };

                var generator = new XamlGenerator(item, xamlg.Language, xamlg.AssemblyName, xamlOutputFile, xamlg.References, null);
                Assert.IsTrue(generator.Execute());

                Assert.IsTrue(xamlg.Execute());
            }
Exemple #13
0
 private void UpdateOutputXaml()
 {
     try
     {
         var xmlDocument = new XmlDocument();
         xmlDocument.LoadXml(metadataXml);
         var configSection = MetadataSerializer.LoadSection(xmlDocument);
         OutputXaml = XamlGenerator.GenerateXaml(configSection);
     }
     catch (Exception e)
     {
         OutputXaml = e.ToString();
     }
 }
        public void GenerateCode(object obj)
        {
            var gen = new XamlGenerator();

            LoadMockup();
            gen.MockupHolder = MockupHolder;
            gen.Generate();
            RequiredNamespaces = gen.NamespaceHeader;
            GeneratedCode      = gen.GeneratedCode;
            WindowXaml         = WindowTemplate.Replace("{Namespaces}", gen.NamespaceHeader).Replace("{Height}", gen.MockupHolder.Mockup.Height.ToString())
                                 .Replace("{Width}", gen.MockupHolder.Mockup.Width.ToString())
                                 .Replace("{LayoutRoot}", gen.GeneratedCode)
                                 .Replace("{Title}", "Title")
                                 .Replace("{Resources}", gen.ResourceHeader);
        }
Exemple #15
0
        //https://github.com/xamarin/Xamarin.Forms/issues/2574
        public void xNameOnRoot()
        {
            var xaml = @"<ContentPage
		xmlns=""http://xamarin.com/schemas/2014/forms""
		xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
		x:Class=""Foo""
		x:Name=""bar"">
	</ContentPage>"    ;

            var generator = new XamlGenerator();

            generator.ParseXaml(new StringReader(xaml));

            Assert.AreEqual(1, generator.NamedFields.Count());
            Assert.AreEqual("bar", generator.NamedFields.First().Name);
            Assert.AreEqual("Xamarin.Forms.ContentPage", generator.NamedFields.First().Type.BaseType);
        }
Exemple #16
0
        //https://bugzilla.xamarin.com/show_bug.cgi?id=33256
        public void AlwaysUseGlobalReference()
        {
            var xaml = @"
			<ContentPage
				xmlns=""http://xamarin.com/schemas/2014/forms""
				xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
				x:Class=""FooBar"" >
				<Label x:Name=""label0""/>
			</ContentPage>"            ;

            using (var reader = new StringReader(xaml)) {
                var generator = new XamlGenerator();
                generator.ParseXaml(reader);

                Assert.IsTrue(generator.BaseType.Options.HasFlag(CodeTypeReferenceOptions.GlobalReference));
                Assert.IsTrue(generator.NamedFields.Select(cmf => cmf.Type).First().Options.HasFlag(CodeTypeReferenceOptions.GlobalReference));
            }
        }
Exemple #17
0
        public void xTypeArgumentsOnRootElement()
        {
            var xaml   = @"<Foo 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" 
							x:TypeArguments=""x:String""
			/>"            ;
            var reader = new StringReader(xaml);

            var generator = new XamlGenerator();

            generator.ParseXaml(reader);

            Assert.AreEqual("FooBar", generator.RootType);
            Assert.AreEqual("Xamarin.Forms.Foo`1", generator.BaseType.BaseType);
            Assert.AreEqual(1, generator.BaseType.TypeArguments.Count);
            Assert.AreEqual("System.String", generator.BaseType.TypeArguments [0].BaseType);
        }
Exemple #18
0
        public void MulipleXTypeArgumentsOnRootElementWithWhitespace()
        {
            var xaml   = @"<Foo 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" 
							x:TypeArguments=""x:String, x:Int32""
			/>"            ;
            var reader = new StringReader(xaml);

            var generator = new XamlGenerator();

            generator.ParseXaml(reader);

            Assert.AreEqual("FooBar", generator.RootType);
            Assert.AreEqual("System.Maui.Foo`2", generator.BaseType.BaseType);
            Assert.AreEqual(2, generator.BaseType.TypeArguments.Count);
            Assert.AreEqual("System.String", generator.BaseType.TypeArguments [0].BaseType);
            Assert.AreEqual("System.Int32", generator.BaseType.TypeArguments [1].BaseType);
        }
Exemple #19
0
        //https://github.com/xamarin/Duplo/issues/1207#issuecomment-47159917
        public void xNameInCustomTypes()
        {
            var xaml = @"<ContentPage
    xmlns=""http://schemas.microsoft.com/dotnet/2021/maui""
    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
    xmlns:local=""clr-namespace:CustomListViewSample;assembly=CustomListViewSample""
    xmlns:localusing=""using:CustomListViewSample""
    x:Class=""CustomListViewSample.TestPage"">
    <StackLayout 
        VerticalOptions=""CenterAndExpand""
        HorizontalOptions=""CenterAndExpand"">
        <Label Text=""Hello, Custom Renderer!"" />
        <local:CustomListView x:Name=""listView""
            WidthRequest=""960"" CornerRadius=""50"" OutlineColor=""Blue"" />
		<localusing:CustomListView x:Name=""listViewusing"" />
    </StackLayout>
</ContentPage>";

            var reader = new StringReader(xaml);

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(reader);

            Assert.AreEqual(2, generator.NamedFields.Count());
            Assert.AreEqual("listView", generator.NamedFields.ToArray()[0].Name);
            Assert.AreEqual("CustomListViewSample.CustomListView", generator.NamedFields.ToArray()[0].Type.BaseType);
            Assert.AreEqual("listViewusing", generator.NamedFields.ToArray()[1].Name);
            Assert.AreEqual("CustomListViewSample.CustomListView", generator.NamedFields.ToArray()[1].Type.BaseType);
        }
Exemple #20
0
        public void MulipleXTypeArgumentsMulitpleNamespacesOnRootElementWithWhitespace()
        {
            var xaml   = @"<Foo 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" 
							x:TypeArguments=""nsone:IDummyInterface, nstwo:IDummyInterfaceTwo""
							xmlns:nsone=""clr-namespace:Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.Interfaces""
							xmlns:nstwo=""clr-namespace:Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.InterfacesTwo""

			/>"            ;
            var reader = new StringReader(xaml);

            var generator = new XamlGenerator();

            generator.ParseXaml(reader);

            Assert.AreEqual("FooBar", generator.RootType);
            Assert.AreEqual("Xamarin.Forms.Foo`2", generator.BaseType.BaseType);
            Assert.AreEqual(2, generator.BaseType.TypeArguments.Count);
            Assert.AreEqual("Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.Interfaces.IDummyInterface", generator.BaseType.TypeArguments [0].BaseType);
            Assert.AreEqual("Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.InterfacesTwo.IDummyInterfaceTwo", generator.BaseType.TypeArguments [1].BaseType);
        }
Exemple #21
0
        public void FieldModifier()
        {
            var xaml = @"
			<ContentPage xmlns=""http://xamarin.com/schemas/2014/forms""
			             xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
			             xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests""
			             x:Class=""Xamarin.Forms.Xaml.UnitTests.FieldModifier"">
				<StackLayout>
			        <Label x:Name=""privateLabel"" />
			        <Label x:Name=""internalLabel"" x:FieldModifier=""NotPublic"" />
			        <Label x:Name=""publicLabel"" x:FieldModifier=""Public"" />
				</StackLayout>
			</ContentPage>"            ;

            using (var reader = new StringReader(xaml))
            {
                var generator = new XamlGenerator();
                generator.ParseXaml(reader);

                Assert.That(generator.NamedFields.First(cmf => cmf.Name == "privateLabel").Attributes, Is.EqualTo(MemberAttributes.Private));
                Assert.That(generator.NamedFields.First(cmf => cmf.Name == "internalLabel").Attributes, Is.EqualTo(MemberAttributes.Assembly));
                Assert.That(generator.NamedFields.First(cmf => cmf.Name == "publicLabel").Attributes, Is.EqualTo(MemberAttributes.Public));
            }
        }
Exemple #22
0
        public void xNameInStyles()
        {
            var xaml   = @"<StackLayout 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" >
							<StackLayout.Resources>
								<ResourceDictionary>
									<Style TargetType=""Label"" >
										<Setter Property=""Text"">
											<Setter.Value>
												<Label x:Name=""notincluded"" />
											</Setter.Value>
										</Setter>
									</Style>
								</ResourceDictionary>
							</StackLayout.Resources>
						</StackLayout>"                        ;
            var reader = new StringReader(xaml);

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(reader);

            Assert.False(generator.NamedFields.Select(cmf => cmf.Name).Contains("notincluded"));
            Assert.AreEqual(0, generator.NamedFields.Count());
        }
Exemple #23
0
        public void xNameInDataTemplates()
        {
            var xaml   = @"<StackLayout 
						    xmlns=""http://xamarin.com/schemas/2014/forms""
						    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
							x:Class=""FooBar"" >
							<ListView>
								<ListView.ItemTemplate>
									<DataTemplate>
										<ViewCell>
											<Label x:Name=""notincluded""/>
										</ViewCell>
									</DataTemplate>
								</ListView.ItemTemplate>
							</ListView>
							<Label x:Name=""included""/>
						</StackLayout>"                        ;
            var reader = new StringReader(xaml);

            var references = string.Join(";",
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.dll")),
                                         IOPath.GetFullPath(
                                             IOPath.Combine(
                                                 TestContext.CurrentContext.TestDirectory, "Microsoft.Maui.Controls.dll"))
                                         );

            var generator = new XamlGenerator(null, null, null, null, null, null, references);

            generator.ParseXaml(reader);

            Assert.Contains("included", generator.NamedFields.Select(cmf => cmf.Name).ToList());
            Assert.False(generator.NamedFields.Select(cmf => cmf.Name).Contains("notincluded"));
            Assert.AreEqual(1, generator.NamedFields.Count());
        }