public async Task Should_Generate_FindControl_Refs_From_Avalonia_Markup_File( string expectation, string markup, bool devToolsMode) { var excluded = devToolsMode ? null : "Avalonia.Diagnostics"; var compilation = View.CreateAvaloniaCompilation(excluded) .WithCustomTextBox(); var types = new RoslynTypeSystem(compilation); var classResolver = new XamlXViewResolver( types, MiniCompiler.CreateDefault( new RoslynTypeSystem(compilation), MiniCompiler.AvaloniaXmlnsDefinitionAttribute)); var xaml = await View.Load(markup); var classInfo = classResolver.ResolveView(xaml); var nameResolver = new XamlXNameResolver(); var names = nameResolver.ResolveNames(classInfo.Xaml); var generator = new InitializeComponentCodeGenerator(types); var code = generator .GenerateCode("SampleView", "Sample.App", classInfo.XamlType, names) .Replace("\r", string.Empty); var expected = await InitializeComponentCode.Load(expectation); CSharpSyntaxTree.ParseText(code); Assert.Equal(expected.Replace("\r", string.Empty), code); }
public void Should_Throw_When_Unable_To_Resolve_Types_From_Simple_Invalid_Markup() { var xaml = XDocumentXamlParser.Parse(MiniInvalidXaml); var compilation = CreateBasicCompilation(MiniClass); var compiler = MiniCompiler.CreateDefault(new RoslynTypeSystem(compilation)); Assert.Throws <XamlParseException>(() => compiler.Transform(xaml)); }
public void Should_Resolve_Types_From_Simple_Avalonia_Markup() { var xaml = XDocumentXamlParser.Parse(AvaloniaXaml); var compilation = View.CreateAvaloniaCompilation(); MiniCompiler.CreateDefault(new RoslynTypeSystem(compilation)).Transform(xaml); Assert.NotNull(xaml.Root); }
public void Should_Resolve_Types_From_Simple_Valid_Xaml_Markup() { var xaml = XDocumentXamlParser.Parse(MiniValidXaml); var compilation = CreateBasicCompilation(MiniClass); MiniCompiler.CreateDefault(new RoslynTypeSystem(compilation)).Transform(xaml); Assert.NotNull(xaml.Root); }
private static IReadOnlyList <ResolvedName> ResolveNames(string xaml) { var compilation = View.CreateAvaloniaCompilation() .WithCustomTextBox(); var classResolver = new XamlXViewResolver( new RoslynTypeSystem(compilation), MiniCompiler.CreateDefault( new RoslynTypeSystem(compilation), MiniCompiler.AvaloniaXmlnsDefinitionAttribute)); var classInfo = classResolver.ResolveView(xaml); var nameResolver = new XamlXNameResolver(); return(nameResolver.ResolveNames(classInfo.Xaml)); }
public async Task Should_Resolve_Base_Class_From_Xaml_File(string nameSpace, string className, string markup) { var xaml = await View.Load(markup); var compilation = View .CreateAvaloniaCompilation() .WithCustomTextBox(); var types = new RoslynTypeSystem(compilation); var resolver = new XamlXViewResolver( types, MiniCompiler.CreateDefault(types, MiniCompiler.AvaloniaXmlnsDefinitionAttribute)); var resolvedClass = resolver.ResolveView(xaml); Assert.Equal(className, resolvedClass.ClassName); Assert.Equal(nameSpace, resolvedClass.Namespace); }
private static INameGenerator CreateNameGenerator(GeneratorExecutionContext context) { var options = new GeneratorOptions(context); var types = new RoslynTypeSystem((CSharpCompilation)context.Compilation); var defaultFieldModifier = options.AvaloniaNameGeneratorDefaultFieldModifier.ToString().ToLowerInvariant(); ICodeGenerator generator = options.AvaloniaNameGeneratorBehavior switch { Behavior.OnlyProperties => new OnlyPropertiesCodeGenerator(), Behavior.InitializeComponent => new InitializeComponentCodeGenerator(types), _ => throw new ArgumentOutOfRangeException() }; var compiler = MiniCompiler.CreateDefault(types, MiniCompiler.AvaloniaXmlnsDefinitionAttribute); return new AvaloniaNameGenerator( new GlobPatternGroup(options.AvaloniaNameGeneratorFilterByPath), new GlobPatternGroup(options.AvaloniaNameGeneratorFilterByNamespace), new XamlXViewResolver(types, compiler, true, type => ReportInvalidType(context, type)), new XamlXNameResolver(defaultFieldModifier), generator); }