Esempio n. 1
0
        /// <summary>Initializes a new instance of the <see cref="FreezeResourceOptimization"/> class.</summary>
        /// <param name="xamlPlatformInfo">The xaml platform information.</param>
        /// <param name="freezeResourceSettings">The freeze resource settings.</param>
        public FreezeResourceOptimization(XamlPlatformInfo xamlPlatformInfo, FreezeResourceSettings freezeResourceSettings)
        {
            this.xamlPlatformInfo = xamlPlatformInfo;
            this.includedTypes    = freezeResourceSettings.IncludeFrameworkTypes
                ? this.GetDefaultIncludedTypes(DefaultFreezables)
                : new HashSet <XName>();
            foreach (var includedType in freezeResourceSettings.IncludedTypes)
            {
                var xName = XName.Get(includedType);
                if (xName.Namespace == XNamespace.None)
                {
                    xName = this.xamlPlatformInfo.PresentationNamespace + includedType;
                }

                this.includedTypes.Add(xName);
            }

            foreach (var excludedType in freezeResourceSettings.ExcludedTypes)
            {
                var xName = XName.Get(excludedType);
                if (xName.Namespace == XNamespace.None)
                {
                    xName = this.xamlPlatformInfo.PresentationNamespace + excludedType;
                }

                this.includedTypes.Remove(xName);
            }
        }
Esempio n. 2
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);
        }
        public BindingXamlPlatformInfo(XamlPlatformInfo xamlPlatformInfo, BindingCompilerSettings bindingCompilerSettings)
        {
            this.XamlPlatformInfo                   = xamlPlatformInfo;
            this.DataTriggerName                    = xamlPlatformInfo.PresentationNamespace + "DataTrigger";
            this.SetterName                         = xamlPlatformInfo.PresentationNamespace + "Setter";
            this.ApplicationName                    = xamlPlatformInfo.PresentationNamespace + "Application";
            this.SundewXamlNamespace                = "http://sundew.dev/xaml";
            this.DesignerDataContextName            = xamlPlatformInfo.DesignerNamespace + "DataContext";
            this.SundewBindingsDataTypeName         = this.SundewXamlNamespace + "Bindings.DataType";
            this.SundewBindingsOptimizeBindingsName = this.SundewXamlNamespace + "Bindings.OptimizeBindings";
            this.XClassName                         = xamlPlatformInfo.XamlNamespace + "Class";
            this.XKeyName = xamlPlatformInfo.XamlNamespace + "Key";
            this.DataTemplateDefinitions = new List <TypedTemplateDefinition>
            {
                new TypedTemplateDefinition(xamlPlatformInfo.PresentationNamespace + "DataTemplate", "DataType"),
                new TypedTemplateDefinition(xamlPlatformInfo.PresentationNamespace + "HierarchicalDataTemplate", "DataType"),
                new TypedTemplateDefinition(xamlPlatformInfo.PresentationNamespace + "ItemContainerTemplate", "DataType"),
            };

            this.ControlTemplateDefinitions = new List <TypedTemplateDefinition>
            {
                new TypedTemplateDefinition(xamlPlatformInfo.PresentationNamespace + "ControlTemplate", "TargetType"),
            };

            this.ItemsPanelTemplateDefinitions = new List <UntypedTemplateDefinition>
            {
                new UntypedTemplateDefinition(xamlPlatformInfo.PresentationNamespace + "ItemsPanelTemplate"),
            };

            this.UnsupportedElements = new List <XName> {
                this.DataTriggerName, this.SetterName
            };

            this.ReadOnlyDependencyPropertyNotificationEvents = new Lazy <IReadOnlyDictionary <string, IReadOnlyDictionary <string, ReadOnlyDependencyPropertyToNotificationEvent> > >(() =>
            {
                var defaultReadOnlyDependencyPropertyNotificationEvents = xamlPlatformInfo.XamlPlatform switch
                {
                    XamlPlatform.WPF => DefaultReadOnlyDependencyPropertyToNotificationEventWpf,
                    XamlPlatform.UWP => DefaultReadOnlyDependencyPropertyToNotificationEventUwp,
                    _ => throw this.CreateXamlPlatformNotSupportedException(),
                };

                return(new CombinedDictionary <string, IReadOnlyDictionary <string, ReadOnlyDependencyPropertyToNotificationEvent> >(bindingCompilerSettings.ReadOnlyDependencyPropertyToNotificationEvents ?? new Dictionary <string, IReadOnlyDictionary <string, ReadOnlyDependencyPropertyToNotificationEvent> >(), defaultReadOnlyDependencyPropertyNotificationEvents.Value));
            });

            this.XamlTypeToSourceCodeNamespaces = new Lazy <IReadOnlyDictionary <string, IReadOnlyDictionary <string, Namespace> > >(
                () =>
            {
                var defaultDefaultXamlTypeToSourceCodeNamespace = this.XamlPlatformInfo.XamlPlatform switch
                {
                    XamlPlatform.WPF => DefaultXamlTypeToSourceCodeNamespaceWpf,
                    XamlPlatform.UWP => DefaultXamlTypeToSourceCodeNamespaceUwp,
                    _ => throw this.CreateXamlPlatformNotSupportedException(),
                };

                return(new CombinedDictionary <string, IReadOnlyDictionary <string, Namespace> >(bindingCompilerSettings.XamlTypeToSourceCodeTypes ?? new Dictionary <string, IReadOnlyDictionary <string, Namespace> >(), defaultDefaultXamlTypeToSourceCodeNamespace.Value));
            });

            this.OneWayBindingProperties = new Lazy <IReadOnlyDictionary <string, IReadOnlyCollection <string> > >(
                () =>
            {
                var defaultDefaultOneWayBindingProperties = this.XamlPlatformInfo.XamlPlatform switch
                {
                    XamlPlatform.WPF => DefaultOneWayBindingPropertiesWpf,
                    XamlPlatform.UWP => new Lazy <IReadOnlyDictionary <string, IReadOnlyCollection <string> > >(() => new Dictionary <string, IReadOnlyCollection <string> >()),
                    _ => throw this.CreateXamlPlatformNotSupportedException(),
                };

                return(new CombinedDictionary <string, IReadOnlyCollection <string> >(bindingCompilerSettings.OneWayBindingProperties ?? new Dictionary <string, IReadOnlyCollection <string> >(), defaultDefaultOneWayBindingProperties.Value));
            });
            switch (xamlPlatformInfo.XamlPlatform)
            {
            case XamlPlatform.WPF:
                this.SundewBindingsXamlNamespace = "clr-namespace:Sundew.Xaml.Optimizations.Bindings;assembly=Sundew.Xaml.Wpf";
                this.UpdateSourceTriggerType     = UpdateSourceTriggerTypeWpf;
                this.BindingModeType             = BindingModeTypeWpf;
                break;

            case XamlPlatform.UWP:
                this.SundewBindingsXamlNamespace = "clr-namespace:Sundew.Xaml.Optimizations.Bindings;assembly=Sundew.Xaml.Uwp";
                this.UpdateSourceTriggerType     = UpdateSourceTriggerTypeUwp;
                this.BindingModeType             = BindingModeTypeUwp;
                break;

            default:
                throw this.CreateXamlPlatformNotSupportedException();
            }
        }
 /// <summary>Initializes a new instance of the <see cref="BindingCompilerOptimization"/> class.</summary>
 /// <param name="xamlPlatformInfo">The xaml platform information.</param>
 /// <param name="projectInfo">The project info.</param>
 /// <param name="bindingCompilerSettings">The binding compiler settings.</param>
 public BindingCompilerOptimization(XamlPlatformInfo xamlPlatformInfo, ProjectInfo projectInfo, BindingCompilerSettings bindingCompilerSettings)
     : this(xamlPlatformInfo, projectInfo, bindingCompilerSettings, new FileSystem())
 {
 }
 public ResourceDictionaryCachingOptimizerTests()
 {
     this.xamlPlatformInfo = new XamlPlatformInfo(XamlPlatform.WPF, Constants.WpfPresentationNamespace, Constants.SundewXamlOptimizationWpfNamespace);
 }
 /// <summary>Initializes a new instance of the <see cref="ResourceDictionaryCachingOptimization"/> class.</summary>
 /// <param name="xamlPlatformInfo">The framework XML definitions.</param>
 public ResourceDictionaryCachingOptimization(XamlPlatformInfo xamlPlatformInfo)
 {
     this.xamlPlatformInfo = xamlPlatformInfo;
     this.sundewXamlResourceDictionaryName = xamlPlatformInfo.SundewXamlOptimizationsNamespace + Constants.ResourceDictionaryName;
 }
 public FreezeResourceOptimizerTests()
 {
     this.xamlPlatformInfo = new XamlPlatformInfo(XamlPlatform.WPF, Constants.WpfPresentationNamespace, Constants.SundewXamlOptimizationWpfNamespace);
 }
 public BindingOptimizationWriter(DirectoryInfo intermediateDirectory, XamlPlatformInfo xamlPlatformInfo, IFileSystem fileSystem)
 {
     this.intermediateDirectory = intermediateDirectory;
     this.xamlPlatformInfo      = xamlPlatformInfo;
     this.fileSystem            = fileSystem;
 }