Пример #1
0
        public async Task Parse_Then_BindingTreeToStringVisitorShouldOutputExpectedResult(string inputFile, string expectedResultFile)
        {
            var xDocument = await LoadXDocument(inputFile).ConfigureAwait(false);

            var xamlPlatformInfo        = XamlPlatformInfoProvider.GetXamlPlatformInfo(XamlPlatform.WPF);
            var bindingXamlPlatformInfo = new BindingXamlPlatformInfo(xamlPlatformInfo,
                                                                      new BindingCompilerSettings(
                                                                          new Dictionary <string, IReadOnlyDictionary <string, ReadOnlyDependencyPropertyToNotificationEvent> >(),
                                                                          new Dictionary <string, IReadOnlyDictionary <string, Namespace> >(),
                                                                          new Dictionary <string, IReadOnlyCollection <string> >()));
            var testee = new BindingTreeParser(
                bindingXamlPlatformInfo,
                new BindingMarkupExtensionParser(new BindingPathParser(new BindingPathLexicalAnalyzer())),
                false);

            var bindingTree = testee.Parse(
                xDocument.Root,
                Path.GetDirectoryName(inputFile),
                Path.GetFileNameWithoutExtension(inputFile),
                XamlTypeResolver.FromXDocument(xDocument, "Sundew.Xaml.Optimizations.TestData.ApiDesigner.Wpf", new IAssemblyReference[0], bindingXamlPlatformInfo.XamlTypeToSourceCodeNamespaces),
                new XamlElementNameResolver(xamlPlatformInfo.XamlNamespace));

            var visitor        = new BindingTreeToStringVisitor();
            var result         = visitor.Visit(bindingTree, null, 0);
            var expectedResult = GetExpectedResult(expectedResultFile);

            result.Should().Be(expectedResult);
        }
 public TargetBindingPartCodeGenerator(SourceBindingCodeGenerator sourceBindingCodeGenerator, BindingModeResolver bindingModeResolver, TypeResolver typeResolver, BindingXamlPlatformInfo bindingXamlPlatformInfo)
 {
     this.sourceBindingCodeGenerator = sourceBindingCodeGenerator;
     this.bindingModeResolver        = bindingModeResolver;
     this.typeResolver            = typeResolver;
     this.bindingXamlPlatformInfo = bindingXamlPlatformInfo;
 }
Пример #3
0
 public BindingTreeParser(
     BindingXamlPlatformInfo bindingXamlPlatformInfo,
     BindingMarkupExtensionParser bindingMarkupExtensionParser,
     bool optInToOptimizations)
 {
     this.bindingXamlPlatformInfo      = bindingXamlPlatformInfo;
     this.bindingMarkupExtensionParser = bindingMarkupExtensionParser;
     this.optInToOptimizations         = optInToOptimizations;
 }
        public BindingPathCodeGenerator(
            TypeResolver typeResolver,
            BindingXamlPlatformInfo bindingXamlPlatformInfo,
            ReadOnlyDependencyPropertyToNotificationEventResolver readOnlyDependencyPropertyToNotificationEventResolver,
            BindingModeResolver bindingModeResolver,
            TypeAssignmentCompatibilityAssessor typeAssignmentCompatibilityAssessor)
        {
            this.typeResolver = typeResolver;
            var sourceBindingCodeGenerator = new SourceBindingCodeGenerator(this.typeResolver, readOnlyDependencyPropertyToNotificationEventResolver);

            this.targetBindingCodeGenerator     = new TargetBindingCodeGenerator(this.typeResolver, bindingModeResolver, typeAssignmentCompatibilityAssessor, bindingXamlPlatformInfo, sourceBindingCodeGenerator);
            this.targetBindingPartCodeGenerator = new TargetBindingPartCodeGenerator(sourceBindingCodeGenerator, bindingModeResolver, this.typeResolver, bindingXamlPlatformInfo);
        }
 public TargetBindingCodeGenerator(
     TypeResolver typeResolver,
     BindingModeResolver bindingModeResolver,
     TypeAssignmentCompatibilityAssessor typeAssignmentCompatibilityAssessor,
     BindingXamlPlatformInfo bindingXamlPlatformInfo,
     SourceBindingCodeGenerator sourceBindingCodeGenerator)
 {
     this.typeResolver        = typeResolver;
     this.bindingModeResolver = bindingModeResolver;
     this.typeAssignmentCompatibilityAssessor = typeAssignmentCompatibilityAssessor;
     this.bindingXamlPlatformInfo             = bindingXamlPlatformInfo;
     this.sourceBindingCodeGenerator          = sourceBindingCodeGenerator;
 }
Пример #6
0
 public BindingContainerCodeGeneratorTests()
 {
     this.xamlPlatformInfo        = XamlPlatformInfoProvider.GetXamlPlatformInfo(XamlPlatform.WPF);
     this.bindingXamlPlatformInfo = new BindingXamlPlatformInfo(this.xamlPlatformInfo,
                                                                new BindingCompilerSettings(
                                                                    new Dictionary <string, IReadOnlyDictionary <string, ReadOnlyDependencyPropertyToNotificationEvent> >(),
                                                                    new Dictionary <string, IReadOnlyDictionary <string, Namespace> >(),
                                                                    new Dictionary <string, IReadOnlyCollection <string> >(),
                                                                    false));
     this.fileSystem = Substitute.For <IFileSystem>();
     this.bindingContainerXamlModificationCollector = new BindingContainerXamlModificationCollector();
     this.bindingOptimizationWriter = new BindingOptimizationWriter(new DirectoryInfo(@"c:\temp\sxo"), xamlPlatformInfo, this.fileSystem);
     this.fileSystem.File.ReadAllText(Arg.Any <string>()).Returns(info => ReadResourceStreamToEnd(info.Arg <string>()));
 }
        internal BindingCompilerOptimization(XamlPlatformInfo xamlPlatformInfo, ProjectInfo projectInfo, BindingCompilerSettings bindingCompilerSettings, IFileSystem fileSystem)
        {
            this.xamlPlatformInfo        = xamlPlatformInfo;
            this.projectInfo             = projectInfo;
            this.useSourceGenerator      = bindingCompilerSettings.UseSourceGenerator;
            this.bindingXamlPlatformInfo = new BindingXamlPlatformInfo(xamlPlatformInfo, bindingCompilerSettings);
            this.bindingTreeParser       = new BindingTreeParser(
                this.bindingXamlPlatformInfo,
                new BindingMarkupExtensionParser(new BindingPathParser(new BindingPathLexicalAnalyzer())),
                bindingCompilerSettings.OptInToOptimizations);
            var codeAnalyzer = new CodeAnalyzer(
                this.projectInfo.AssemblyName,
                this.projectInfo.Compiles,
                this.projectInfo.AssemblyReferences,
                fileSystem.File,
                new XamlTypeBaseTypeSourceCodeGenerator(
                    this.projectInfo.XDocumentProvider,
                    this.bindingXamlPlatformInfo.XClassName,
                    this.projectInfo.AssemblyName,
                    this.projectInfo.AssemblyReferences,
                    this.bindingXamlPlatformInfo.XamlTypeToSourceCodeNamespaces),
                !bindingCompilerSettings.UseSourceGenerator);

            this.typeResolver = new TypeResolver(codeAnalyzer);
            this.bindingOptimizationWriter = new BindingOptimizationWriter(this.projectInfo.IntermediateDirectory, xamlPlatformInfo, fileSystem);
            this.bindingContainerXamlModificationCollector = new BindingContainerXamlModificationCollector();
            this.bindingContainerCodeGenerator             = new BindingContainerCodeGenerator(
                new BindingPathCodeGenerator(
                    this.typeResolver,
                    this.bindingXamlPlatformInfo,
                    new ReadOnlyDependencyPropertyToNotificationEventResolver(codeAnalyzer, this.bindingXamlPlatformInfo.ReadOnlyDependencyPropertyNotificationEvents),
                    new BindingModeResolver(this.bindingXamlPlatformInfo.OneWayBindingProperties, codeAnalyzer, xamlPlatformInfo.XamlPlatform),
                    new TypeAssignmentCompatibilityAssessor(codeAnalyzer)),
                this.bindingXamlPlatformInfo,
                this.typeResolver);
        }
Пример #8
0
 public BindingContainerCodeGenerator(IBindingPathVisitor <BindingPath.Parameters, BindingPath.Context, Result.IfSuccess <BindingSource>, Result.IfSuccess <CodeInfo> > bindingPathCodeGenerator, BindingXamlPlatformInfo bindingXamlPlatformInfo, TypeResolver typeResolver)
 {
     this.bindingPathCodeGenerator = bindingPathCodeGenerator;
     this.bindingXamlPlatformInfo  = bindingXamlPlatformInfo;
     this.typeResolver             = typeResolver;
 }