Exemple #1
0
        private static void BuildEndPointAttribute(GeneratorExecutionContext context, IndentedStringBuilder sb)
        {
            var unoRemoteControlPort = context.GetMSBuildPropertyValue("UnoRemoteControlPort");

            if (string.IsNullOrEmpty(unoRemoteControlPort))
            {
                unoRemoteControlPort = "0";
            }

            var unoRemoteControlHost = context.GetMSBuildPropertyValue("UnoRemoteControlHost");

            if (string.IsNullOrEmpty(unoRemoteControlHost))
            {
                var addresses = NetworkInterface.GetAllNetworkInterfaces()
                                .SelectMany(x => x.GetIPProperties().UnicastAddresses)
                                .Where(x => !IPAddress.IsLoopback(x.Address));

                foreach (var addressInfo in addresses)
                {
                    sb.AppendLineInvariant($"[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute(\"{addressInfo.Address}\", {unoRemoteControlPort})]");
                }
            }
            else
            {
                sb.AppendLineInvariant($"[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute(\"{unoRemoteControlHost}\", {unoRemoteControlPort})]");
            }
        }
Exemple #2
0
        private static void BuildSearchPaths(GeneratorExecutionContext context, IndentedStringBuilder sb)
        {
            sb.AppendLineInvariant($"[assembly: global::Uno.UI.RemoteControl.ProjectConfigurationAttribute(");
            sb.AppendLineInvariant($"@\"{context.GetMSBuildPropertyValue("MSBuildProjectFullPath")}\",\n");

            var msBuildProjectDirectory = context.GetMSBuildPropertyValue("MSBuildProjectDirectory");
            var sources = new[] {
                "Page",
                "ApplicationDefinition",
                "ProjectReference",
            };

            IEnumerable <string> BuildSearchPath(string s)
            => context
            .GetMSBuildItems(s)
            .Select(v => Path.IsPathRooted(v.Identity) ? v.Identity : Path.Combine(msBuildProjectDirectory, v.Identity));

            var xamlPaths = from item in sources.SelectMany(BuildSearchPath)
                            select Path.GetDirectoryName(item);

            var distictPaths = string.Join(",\n", xamlPaths.Distinct().Select(p => $"@\"{p}\""));

            sb.AppendLineInvariant("{0}", $"new string[]{{{distictPaths}}}");

            sb.AppendLineInvariant(")]");
        }
Exemple #3
0
        public static bool IsValidPlatform(GeneratorExecutionContext context)
        {
            var evaluatedValue   = context.GetMSBuildPropertyValue("TargetPlatformIdentifier");
            var useWPF           = context.GetMSBuildPropertyValue("UseWPF");
            var projectTypeGuids = context.GetMSBuildPropertyValue("ProjectTypeGuidsProperty");

            var isUAP            = evaluatedValue?.Equals("UAP", StringComparison.OrdinalIgnoreCase) ?? false;
            var isNetCoreWPF     = useWPF?.Equals("True", StringComparison.OrdinalIgnoreCase) ?? false;
            var isNetCoreDesktop = projectTypeGuids == "{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}";

            return(!isUAP && !isNetCoreWPF && !isNetCoreDesktop);
        }
Exemple #4
0
        internal static bool IsApplication(GeneratorExecutionContext context)
        {
            var isAndroidApp = context.GetMSBuildPropertyValue("AndroidApplication")?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false;
            var isiOSApp     = context.GetMSBuildPropertyValue("ProjectTypeGuidsProperty")?.Equals("{FEACFBD2-3405-455C-9665-78FE426C6842},{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", StringComparison.OrdinalIgnoreCase) ?? false;
            var ismacOSApp   = context.GetMSBuildPropertyValue("ProjectTypeGuidsProperty")?.Equals("{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1},{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", StringComparison.OrdinalIgnoreCase) ?? false;
            var isExe        = context.GetMSBuildPropertyValue("OutputType")?.Equals("Exe", StringComparison.OrdinalIgnoreCase) ?? false;
            var isUnoHead    = context.GetMSBuildPropertyValue("IsUnoHead")?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false;

            return(isAndroidApp ||
                   (isiOSApp && isExe) ||
                   (ismacOSApp && isExe) ||
                   isUnoHead);
        }
Exemple #5
0
        public static bool IsDesignTime(GeneratorExecutionContext context)
        {
#if NETFRAMEWORK
            // Uno source generators do not support design-time generation
            return(false);
#else
            var isBuildingProjectValue = context.GetMSBuildPropertyValue("BuildingProject");             // legacy projects
            var isDesignTimeBuildValue = context.GetMSBuildPropertyValue("DesignTimeBuild");             // sdk-style projects

            return(string.Equals(isBuildingProjectValue, "false", StringComparison.OrdinalIgnoreCase) ||
                   string.Equals(isDesignTimeBuildValue, "true", StringComparison.OrdinalIgnoreCase));
#endif
        }
        public void Execute(GeneratorExecutionContext context)
        {
            if (!DesignTimeHelper.IsDesignTime(context))
            {
                _bindingsPaths    = context.GetMSBuildPropertyValue("TSBindingsPath")?.ToString();
                _sourceAssemblies = context.GetMSBuildItems("TSBindingAssemblySource").Select(i => i.Identity).ToArray();

                if (!string.IsNullOrEmpty(_bindingsPaths))
                {
                    Directory.CreateDirectory(_bindingsPaths);

                    _intPtrSymbol         = context.Compilation.GetTypeByMetadataName("System.IntPtr");
                    _structLayoutSymbol   = context.Compilation.GetTypeByMetadataName(typeof(StructLayoutAttribute).FullName);
                    _interopMessageSymbol = context.Compilation.GetTypeByMetadataName("Uno.Foundation.Interop.TSInteropMessageAttribute");

                    var modules = from ext in context.Compilation.ExternalReferences
                                  let sym = context.Compilation.GetAssemblyOrModuleSymbol(ext) as IAssemblySymbol
                                            where _sourceAssemblies.Contains(sym.Name)
                                            from module in sym.Modules
                                            select module;

                    modules = modules.Concat(context.Compilation.SourceModule);

                    GenerateTSMarshallingLayouts(modules);
                }
            }
        }
Exemple #7
0
        public void Execute(GeneratorExecutionContext context)
        {
            if (
                !DesignTimeHelper.IsDesignTime(context) &&
                context.GetMSBuildPropertyValue("Configuration") == "Debug" &&
                IsRemoteControlClientInstalled(context) &&
                PlatformHelper.IsApplication(context))
            {
                var sb = new IndentedStringBuilder();

                sb.AppendLineInvariant("// <auto-generated>");
                sb.AppendLineInvariant("// ***************************************************************************************");
                sb.AppendLineInvariant("// This file has been generated by the package Uno.UI.RemoteControl - for Xaml Hot Reload.");
                sb.AppendLineInvariant("// Documentation: https://platform.uno/docs/articles/features/working-with-xaml-hot-reload.html");
                sb.AppendLineInvariant("// ***************************************************************************************");
                sb.AppendLineInvariant("// </auto-generated>");
                sb.AppendLineInvariant("// <autogenerated />");
                sb.AppendLineInvariant("#pragma warning disable // Ignore code analysis warnings");

                sb.AppendLineInvariant("");

                BuildEndPointAttribute(context, sb);
                BuildSearchPaths(context, sb);
                BuildServerProcessorsPaths(context, sb);

                context.AddSource("RemoteControl", sb.ToString());
            }
        }
        public void Execute(GeneratorExecutionContext context)
        {
            DependenciesInitializer.Init(context);

            if (!DesignTimeHelper.IsDesignTime(context))
            {
                _bindingsPaths    = context.GetMSBuildPropertyValue("TSBindingsPath")?.ToString();
                _sourceAssemblies = context.GetMSBuildItems("TSBindingAssemblySource").Select(i => i.Identity).ToArray();

                if (!string.IsNullOrEmpty(_bindingsPaths))
                {
                    _stringSymbol         = context.Compilation.GetTypeByMetadataName("System.String");
                    _intSymbol            = context.Compilation.GetTypeByMetadataName("System.Int32");
                    _floatSymbol          = context.Compilation.GetTypeByMetadataName("System.Single");
                    _doubleSymbol         = context.Compilation.GetTypeByMetadataName("System.Double");
                    _byteSymbol           = context.Compilation.GetTypeByMetadataName("System.Byte");
                    _shortSymbol          = context.Compilation.GetTypeByMetadataName("System.Int16");
                    _intPtrSymbol         = context.Compilation.GetTypeByMetadataName("System.IntPtr");
                    _boolSymbol           = context.Compilation.GetTypeByMetadataName("System.Boolean");
                    _longSymbol           = context.Compilation.GetTypeByMetadataName("System.Int64");
                    _structLayoutSymbol   = context.Compilation.GetTypeByMetadataName(typeof(System.Runtime.InteropServices.StructLayoutAttribute).FullName);
                    _interopMessageSymbol = context.Compilation.GetTypeByMetadataName("Uno.Foundation.Interop.TSInteropMessageAttribute");

                    var modules = from ext in context.Compilation.ExternalReferences
                                  let sym = context.Compilation.GetAssemblyOrModuleSymbol(ext) as IAssemblySymbol
                                            where _sourceAssemblies.Contains(sym.Name)
                                            from module in sym.Modules
                                            select module;

                    modules = modules.Concat(context.Compilation.SourceModule);

                    GenerateTSMarshallingLayouts(modules);
                }
            }
        }
        public void Execute(GeneratorExecutionContext context)
        {
            try
            {
                var validPlatform = PlatformHelper.IsValidPlatform(context);
                var isDesignTime  = DesignTimeHelper.IsDesignTime(context);
                var isApplication = IsApplication(context);

                if (validPlatform &&
                    !isDesignTime)
                {
                    if (isApplication)
                    {
                        _defaultNamespace   = context.GetMSBuildPropertyValue("RootNamespace");
                        _namedSymbolsLookup = context.Compilation.GetSymbolNameLookup();

                        _bindableAttributeSymbol  = FindBindableAttributes(context);
                        _dependencyPropertySymbol = context.Compilation.GetTypeByMetadataName(XamlConstants.Types.DependencyProperty);

                        _objectSymbol             = context.Compilation.GetTypeByMetadataName("System.Object");
                        _javaObjectSymbol         = context.Compilation.GetTypeByMetadataName("Java.Lang.Object");
                        _nsObjectSymbol           = context.Compilation.GetTypeByMetadataName("Foundation.NSObject");
                        _stringSymbol             = context.Compilation.GetTypeByMetadataName("System.String");
                        _nonBindableSymbol        = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.Data.NonBindableAttribute");
                        _resourceDictionarySymbol = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.ResourceDictionary");
                        _currentModule            = context.Compilation.SourceModule;

                        AnalyzerSuppressions = new string[0];

                        var modules = from ext in context.Compilation.ExternalReferences
                                      let sym = context.Compilation.GetAssemblyOrModuleSymbol(ext) as IAssemblySymbol
                                                where sym != null
                                                from module in sym.Modules
                                                select module;

                        modules = modules.Concat(context.Compilation.SourceModule);

                        context.AddSource("BindableMetadata", GenerateTypeProviders(modules));
                    }
                    else
                    {
                        context.AddSource("BindableMetadata", $"// validPlatform: {validPlatform} designTime:{isDesignTime} isApplication:{isApplication}");
                    }
                }
            }
            catch (Exception e)
            {
                string?message = e.Message + e.StackTrace;

                if (e is AggregateException)
                {
                    message = (e as AggregateException)?.InnerExceptions.Select(ex => ex.Message + e.StackTrace).JoinBy("\r\n");
                }

                this.Log().Error("Failed to generate type providers.", new Exception("Failed to generate type providers." + message, e));
            }
        }
Exemple #10
0
        private static void BuildEndPointAttribute(GeneratorExecutionContext context, IndentedStringBuilder sb)
        {
            var unoRemoteControlPort = context.GetMSBuildPropertyValue("UnoRemoteControlPort");

            if (string.IsNullOrEmpty(unoRemoteControlPort))
            {
                unoRemoteControlPort = "0";
            }

            var unoRemoteControlHost = context.GetMSBuildPropertyValue("UnoRemoteControlHost");

            if (string.IsNullOrEmpty(unoRemoteControlHost))
            {
                var addresses = NetworkInterface.GetAllNetworkInterfaces()
                                .SelectMany(x => x.GetIPProperties().UnicastAddresses)
                                .Where(x => !IPAddress.IsLoopback(x.Address));
                //This is not supported on linux yet: .Where(x => x.DuplicateAddressDetectionState == DuplicateAddressDetectionState.Preferred);

                foreach (var addressInfo in addresses)
                {
                    var address = addressInfo.Address;

                    string addressStr;
                    if (address.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        address.ScopeId = 0;                         // remove annoying "%xx" on IPv6 addresses
                        addressStr      = $"[{address}]";
                    }
                    else
                    {
                        addressStr = address.ToString();
                    }
                    sb.AppendLineInvariant($"[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute(\"{addressStr}\", {unoRemoteControlPort})]");
                }
            }
            else
            {
                sb.AppendLineInvariant($"[assembly: global::Uno.UI.RemoteControl.ServerEndpointAttribute(\"{unoRemoteControlHost}\", {unoRemoteControlPort})]");
            }
        }
Exemple #11
0
        public void Execute(GeneratorExecutionContext context)
        {
            context.AddSource(
                "Test3",
                $@"
				namespace RoslynCompatGeneratorTest {{
					public static class TestType
					{{
						// reusing the compiled code form other generator
						public const int Project = {context.GetMSBuildPropertyValue("MyTestProperty")};
					}}
				}}"                );
        }
Exemple #12
0
        public static bool IsValidPlatform(GeneratorExecutionContext context)
        {
            var evaluatedValue   = context.GetMSBuildPropertyValue("TargetPlatformIdentifier");
            var useWPF           = context.GetMSBuildPropertyValue("UseWPF");
            var projectTypeGuids = context.GetMSBuildPropertyValue("ProjectTypeGuidsProperty");

            var isUAP = evaluatedValue?.Equals("UAP", StringComparison.OrdinalIgnoreCase) ?? false;

            // Those two checks are now required since VS 16.9 which enables source generators by default
            // and the uno targets files are not present for uap targets.
            var isWindowsRuntimeApplicationOutput = context.Compilation.Options.OutputKind == OutputKind.WindowsRuntimeApplication;
            var isWindowsRuntimeMetadataOutput    = context.Compilation.Options.OutputKind == OutputKind.WindowsRuntimeMetadata;

            var isNetCoreWPF     = useWPF?.Equals("True", StringComparison.OrdinalIgnoreCase) ?? false;
            var isNetCoreDesktop = projectTypeGuids?.Equals("{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", StringComparison.OrdinalIgnoreCase) ?? false;

            return(!isUAP &&
                   !isNetCoreWPF &&
                   !isNetCoreDesktop &&
                   !isWindowsRuntimeMetadataOutput &&
                   !isWindowsRuntimeApplicationOutput);
        }
            public SerializationMethodsGenerator(GeneratorExecutionContext context)
            {
                _context = context;

                var comp = context.Compilation;

                _dependencyObjectSymbol  = comp.GetTypeByMetadataName(XamlConstants.Types.DependencyObject);
                _unoViewgroupSymbol      = comp.GetTypeByMetadataName("Uno.UI.UnoViewGroup");
                _iosViewSymbol           = comp.GetTypeByMetadataName("UIKit.UIView");
                _macosViewSymbol         = comp.GetTypeByMetadataName("AppKit.NSView");
                _androidViewSymbol       = comp.GetTypeByMetadataName("Android.Views.View");
                _javaObjectSymbol        = comp.GetTypeByMetadataName("Java.Lang.Object");
                _androidActivitySymbol   = comp.GetTypeByMetadataName("Android.App.Activity");
                _androidFragmentSymbol   = comp.GetTypeByMetadataName("AndroidX.Fragment.App.Fragment");
                _bindableAttributeSymbol = comp.GetTypeByMetadataName("Windows.UI.Xaml.Data.BindableAttribute");
                _iFrameworkElementSymbol = comp.GetTypeByMetadataName(XamlConstants.Types.IFrameworkElement);
                _frameworkElementSymbol  = comp.GetTypeByMetadataName("Windows.UI.Xaml.FrameworkElement");
                _isUnoSolution           = _context.GetMSBuildPropertyValue("_IsUnoUISolution") == "true";
            }
        internal void Update(GeneratorExecutionContext context)
        {
            var intermediateOutputPath = context.GetMSBuildPropertyValue("IntermediateOutputPath");

            if (intermediateOutputPath != null)
            {
                var runFilePath = Path.Combine(intermediateOutputPath, "build-time-generator.touch");

                if (File.Exists(runFilePath))
                {
                    var lastWriteTime = new FileInfo(runFilePath).LastWriteTime;

                    if (lastWriteTime > _previousWriteTime)
                    {
                        _previousWriteTime = lastWriteTime;

                        // Clear the existing runs if a full build has been started
                        _runs.Clear();
                    }
                }
            }

            if (GetIsDesignTimeBuild(context) &&
                !GetIsHotReloadHost(context) &&
                !Process.GetCurrentProcess().ProcessName.Equals("devenv", StringComparison.InvariantCultureIgnoreCase))
            {
                // Design-time builds need to clear runs for the x:Name values to be regenerated, in the context of OmniSharp.
                // In the context of HotReload, we need to skip this, as the HotReload service sets DesignTimeBuild to build
                // to true, preventing existing runs to be kept active.
                //
                // Devenv is also added to the conditions as there's no explicit way
                // for knowing that we're in a hot-reload session.
                //
                _runs.Clear();
            }
        }
Exemple #15
0
 public static bool IsExe(GeneratorExecutionContext context)
 => context.GetMSBuildPropertyValue("OutputType")?.Equals("Exe", StringComparison.OrdinalIgnoreCase) ?? false;
Exemple #16
0
 private void BuildServerProcessorsPaths(GeneratorExecutionContext context, IndentedStringBuilder sb)
 {
     sb.AppendLineInvariant($"[assembly: global::Uno.UI.RemoteControl.ServerProcessorsConfigurationAttribute(" +
                            $"@\"{context.GetMSBuildPropertyValue("UnoRemoteControlProcessorsPath")}\"" +
                            $")]");
 }
Exemple #17
0
            internal void Generate(GeneratorExecutionContext context)
            {
                try
                {
                    var validPlatform = PlatformHelper.IsValidPlatform(context);
                    var isDesignTime  = DesignTimeHelper.IsDesignTime(context);
                    var isApplication = Helpers.IsApplication(context);

                    if (validPlatform &&
                        !isDesignTime)
                    {
                        if (isApplication)
                        {
                            _projectFullPath  = context.GetMSBuildPropertyValue("MSBuildProjectFullPath");
                            _projectDirectory = Path.GetDirectoryName(_projectFullPath)
                                                ?? throw new InvalidOperationException($"MSBuild property MSBuildProjectFullPath value {_projectFullPath} is not valid");

                            if (!bool.TryParse(context.GetMSBuildPropertyValue("UnoXamlResourcesTrimming"), out _xamlResourcesTrimming))
                            {
                                _xamlResourcesTrimming = false;
                            }

                            _baseIntermediateOutputPath = context.GetMSBuildPropertyValue("BaseIntermediateOutputPath");
                            _intermediatePath           = Path.Combine(
                                _projectDirectory,
                                _baseIntermediateOutputPath
                                );
                            _assemblyName = context.GetMSBuildPropertyValue("AssemblyName");

                            _defaultNamespace   = context.GetMSBuildPropertyValue("RootNamespace");
                            _namedSymbolsLookup = context.Compilation.GetSymbolNameLookup();

                            _bindableAttributeSymbol  = FindBindableAttributes(context);
                            _dependencyPropertySymbol = context.Compilation.GetTypeByMetadataName(XamlConstants.Types.DependencyProperty);
                            _dependencyObjectSymbol   = context.Compilation.GetTypeByMetadataName(XamlConstants.Types.DependencyObject);

                            _objectSymbol             = context.Compilation.GetTypeByMetadataName("System.Object");
                            _javaObjectSymbol         = context.Compilation.GetTypeByMetadataName("Java.Lang.Object");
                            _nsObjectSymbol           = context.Compilation.GetTypeByMetadataName("Foundation.NSObject");
                            _stringSymbol             = context.Compilation.GetTypeByMetadataName("System.String");
                            _nonBindableSymbol        = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.Data.NonBindableAttribute");
                            _resourceDictionarySymbol = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.ResourceDictionary");
                            _currentModule            = context.Compilation.SourceModule;

                            AnalyzerSuppressions = new string[0];

                            var modules = from ext in context.Compilation.ExternalReferences
                                          let sym = context.Compilation.GetAssemblyOrModuleSymbol(ext) as IAssemblySymbol
                                                    where sym != null
                                                    from module in sym.Modules
                                                    select module;

                            modules = modules.Concat(context.Compilation.SourceModule);

                            context.AddSource("BindableMetadata", GenerateTypeProviders(modules));

                            GenerateLinkerSubstitutionDefinition();
                        }
                        else
                        {
                            context.AddSource("BindableMetadata", $"// validPlatform: {validPlatform} designTime:{isDesignTime} isApplication:{isApplication}");
                        }
                    }
                }
                catch (Exception e)
                {
                    string?message = e.Message + e.StackTrace;

                    if (e is AggregateException)
                    {
                        message = (e as AggregateException)?.InnerExceptions.Select(ex => ex.Message + e.StackTrace).JoinBy("\r\n");
                    }

                    this.Log().Error("Failed to generate type providers.", new Exception("Failed to generate type providers." + message, e));
                }
            }
Exemple #18
0
 public static bool IsMacOs(GeneratorExecutionContext context)
 => context.GetMSBuildPropertyValue("ProjectTypeGuidsProperty")?.Equals("{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1},{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", StringComparison.OrdinalIgnoreCase) ?? false;
            private void ProcessType(INamedTypeSymbol typeSymbol)
            {
                _context.CancellationToken.ThrowIfCancellationRequested();

                if (typeSymbol.TypeKind != TypeKind.Class)
                {
                    return;
                }

                var isDependencyObject = typeSymbol.Interfaces.Any(t => SymbolEqualityComparer.Default.Equals(t, _dependencyObjectSymbol)) &&
                                         (typeSymbol.BaseType?.GetAllInterfaces().None(t => SymbolEqualityComparer.Default.Equals(t, _dependencyObjectSymbol)) ?? true);

                if (isDependencyObject)
                {
                    if (_context.GetMSBuildPropertyValue("_IsUnoUISolution") != "true")
                    {
                        if (typeSymbol.Is(_iosViewSymbol))
                        {
                            throw new InvalidOperationException("A 'UIKit.UIView' shouldn't implement 'DependencyObject'. Inherit 'FrameworkElement' instead.");
                        }
                        else if (typeSymbol.Is(_androidViewSymbol))
                        {
                            throw new InvalidOperationException("An 'Android.Views.View' shouldn't implement 'DependencyObject'. Inherit 'FrameworkElement' instead.");
                        }
                        else if (typeSymbol.Is(_macosViewSymbol))
                        {
                            throw new InvalidOperationException("An 'AppKit.NSView' shouldn't implement 'DependencyObject'. Inherit 'FrameworkElement' instead.");
                        }
                    }

                    var builder = new IndentedStringBuilder();
                    builder.AppendLineInvariant("// <auto-generated>");
                    builder.AppendLineInvariant("// ******************************************************************");
                    builder.AppendLineInvariant("// This file has been generated by Uno.UI (DependencyObjectGenerator)");
                    builder.AppendLineInvariant("// ******************************************************************");
                    builder.AppendLineInvariant("// </auto-generated>");
                    builder.AppendLine();
                    builder.AppendLineInvariant("#pragma warning disable 1591 // Ignore missing XML comment warnings");
                    builder.AppendLineInvariant($"using System;");
                    builder.AppendLineInvariant($"using System.Linq;");
                    builder.AppendLineInvariant($"using System.Collections.Generic;");
                    builder.AppendLineInvariant($"using System.Collections;");
                    builder.AppendLineInvariant($"using System.Diagnostics.CodeAnalysis;");
                    builder.AppendLineInvariant($"using Uno.Disposables;");
                    builder.AppendLineInvariant($"using System.Runtime.CompilerServices;");
                    builder.AppendLineInvariant($"using Uno.Extensions;");
                    builder.AppendLineInvariant($"using Uno.Logging;");
                    builder.AppendLineInvariant($"using Uno.UI;");
                    builder.AppendLineInvariant($"using Uno.UI.DataBinding;");
                    builder.AppendLineInvariant($"using Windows.UI.Xaml;");
                    builder.AppendLineInvariant($"using Windows.UI.Xaml.Data;");
                    builder.AppendLineInvariant($"using Uno.Diagnostics.Eventing;");

                    using (builder.BlockInvariant($"namespace {typeSymbol.ContainingNamespace}"))
                    {
                        using (GenerateNestingContainers(builder, typeSymbol))
                        {
                            if (_bindableAttributeSymbol != null && typeSymbol.FindAttribute(_bindableAttributeSymbol) == null)
                            {
                                builder.AppendLineInvariant(@"[global::Windows.UI.Xaml.Data.Bindable]");
                            }

                            using (builder.BlockInvariant($"partial class {typeSymbol.Name} : IDependencyObjectStoreProvider, IWeakReferenceProvider"))
                            {
                                GenerateDependencyObjectImplementation(builder);
                                GenerateIBinderImplementation(typeSymbol, builder);
                            }
                        }
                    }

                    _context.AddSource(HashBuilder.BuildIDFromSymbol(typeSymbol), builder.ToString());
                }
            }
 private bool GetIsHotReloadHost(GeneratorExecutionContext context)
 {
     return(bool.TryParse(context.GetMSBuildPropertyValue("IsHotReloadHost"), out var value) && value);
 }
 private bool GetIsDesignTimeBuild(GeneratorExecutionContext context)
 {
     return(bool.TryParse(context.GetMSBuildPropertyValue("DesignTimeBuild"), out var value) && value);
 }
Exemple #22
0
            internal void Generate(GeneratorExecutionContext context)
            {
                try
                {
                    var validPlatform = PlatformHelper.IsValidPlatform(context);
                    var isDesignTime  = DesignTimeHelper.IsDesignTime(context);
                    var isApplication = Helpers.IsApplication(context);

                    if (!bool.TryParse(context.GetMSBuildPropertyValue("UnoXamlResourcesTrimming"), out _xamlResourcesTrimming))
                    {
                        _xamlResourcesTrimming = false;
                    }

                    if (validPlatform && _xamlResourcesTrimming)
                    {
                        _defaultNamespace = context.GetMSBuildPropertyValue("RootNamespace");

                        _projectFullPath  = context.GetMSBuildPropertyValue("MSBuildProjectFullPath");
                        _projectDirectory = Path.GetDirectoryName(_projectFullPath)
                                            ?? throw new InvalidOperationException($"MSBuild property MSBuildProjectFullPath value {_projectFullPath} is not valid");

                        _baseIntermediateOutputPath = context.GetMSBuildPropertyValue("BaseIntermediateOutputPath");
                        _intermediatePath           = Path.Combine(
                            _projectDirectory,
                            _baseIntermediateOutputPath
                            );
                        _assemblyName       = context.GetMSBuildPropertyValue("AssemblyName");
                        _namedSymbolsLookup = context.Compilation.GetSymbolNameLookup();

                        _bindableAttributeSymbol  = FindBindableAttributes(context);
                        _dependencyObjectSymbol   = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.DependencyObject");
                        _resourceDictionarySymbol = context.Compilation.GetTypeByMetadataName("Windows.UI.Xaml.ResourceDictionary");
                        _currentModule            = context.Compilation.SourceModule;

                        AnalyzerSuppressions = new string[0];

                        var modules = from ext in context.Compilation.ExternalReferences
                                      let sym = context.Compilation.GetAssemblyOrModuleSymbol(ext) as IAssemblySymbol
                                                where sym != null
                                                from module in sym.Modules
                                                select module;

                        modules = modules.Concat(context.Compilation.SourceModule);

                        var bindableTypes = from module in modules
                                            from type in module.GlobalNamespace.GetNamespaceTypes()
                                            where (
                            (
                                type.GetAllInterfaces().Any(i => SymbolEqualityComparer.Default.Equals(i, _dependencyObjectSymbol))
                            )
                            )
                                            select type;

                        bindableTypes = bindableTypes.ToArray();

                        context.AddSource("DependencyObjectAvailability", GenerateTypeProviders(bindableTypes));

                        GenerateLinkerSubstitutionDefinition(bindableTypes, isApplication);
                    }
                }
                catch (Exception e)
                {
                    string?message = e.Message + e.StackTrace;

                    if (e is AggregateException)
                    {
                        message = (e as AggregateException)?.InnerExceptions.Select(ex => ex.Message + e.StackTrace).JoinBy("\r\n");
                    }

                    this.Log().Error("Failed to generate type providers.", new Exception("Failed to generate type providers." + message, e));
                }
            }
Exemple #23
0
 public static bool IsiOS(GeneratorExecutionContext context)
 => context.GetMSBuildPropertyValue("ProjectTypeGuidsProperty")?.Equals("{FEACFBD2-3405-455C-9665-78FE426C6842},{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", StringComparison.OrdinalIgnoreCase) ?? false;
Exemple #24
0
 public static bool IsUnoHead(GeneratorExecutionContext context)
 => context.GetMSBuildPropertyValue("IsUnoHead")?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false;