Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 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(")]");
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }