Exemple #1
0
            private string GenerateTypeProviders(IEnumerable <INamedTypeSymbol> bindableTypes)
            {
                var writer = new IndentedStringBuilder();

                writer.AppendLineInvariant("// <auto-generated>");
                writer.AppendLineInvariant("// *****************************************************************************");
                writer.AppendLineInvariant("// This file has been generated by Uno.UI (BindableTypeProvidersSourceGenerator)");
                writer.AppendLineInvariant("// *****************************************************************************");
                writer.AppendLineInvariant("// </auto-generated>");
                writer.AppendLine();
                writer.AppendLineInvariant("#pragma warning disable 618  // Ignore obsolete members warnings");
                writer.AppendLineInvariant("#pragma warning disable 1591 // Ignore missing XML comment warnings");
                writer.AppendLineInvariant("using System;");
                writer.AppendLineInvariant("using System.Linq;");
                writer.AppendLineInvariant("using System.Diagnostics;");

                writer.AppendLineInvariant($"// _intermediatePath: {_intermediatePath}");
                writer.AppendLineInvariant($"// _baseIntermediateOutputPath: {_baseIntermediateOutputPath}");

                using (writer.BlockInvariant("namespace {0}", _defaultNamespace))
                {
                    using (writer.BlockInvariant("internal class " + LinkerHintsHelpers.GetLinkerHintsClassName()))
                    {
                        foreach (var type in bindableTypes)
                        {
                            var safeTypeName = LinkerHintsHelpers.GetPropertyAvailableName(type.GetFullMetadataName());

                            writer.AppendLineInvariant($"internal static bool {safeTypeName} => true;");
                        }
                    }
                }

                return(writer.ToString());
            }
Exemple #2
0
            private void GenerateLinkerSubstitutionDefinition(IEnumerable <INamedTypeSymbol> bindableTypes, bool isApplication)
            {
                // <linker>
                //   <assembly fullname="Uno.UI">
                //  <type fullname="Uno.UI.GlobalStaticResources">
                //    <method signature="System.Void Initialize()" body="remove" />
                //    <method signature="System.Void RegisterDefaultStyles()" body="remove" />
                //  </type>
                //   </assembly>
                // </linker>
                var doc = new XmlDocument();

                var xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

                var root = doc.DocumentElement;

                doc.InsertBefore(xmlDeclaration, root);

                var linkerNode = doc.CreateElement(string.Empty, "linker", string.Empty);

                doc.AppendChild(linkerNode);

                var assemblyNode = doc.CreateElement(string.Empty, "assembly", string.Empty);

                assemblyNode.SetAttribute("fullname", _assemblyName);
                linkerNode.AppendChild(assemblyNode);


                //
                // Linker hints features from dependency objects
                //
                var typeNode = doc.CreateElement(string.Empty, "type", string.Empty);

                typeNode.SetAttribute("fullname", LinkerHintsHelpers.GetLinkerHintsClassName(_defaultNamespace));
                assemblyNode.AppendChild(typeNode);

                foreach (var type in bindableTypes)
                {
                    var propertyName = LinkerHintsHelpers.GetPropertyAvailableName(type.GetFullMetadataName());

                    var methodNode = doc.CreateElement(string.Empty, "method", string.Empty);
                    methodNode.SetAttribute("signature", $"System.Boolean get_{propertyName}()");
                    methodNode.SetAttribute("body", "stub");
                    methodNode.SetAttribute("value", "false");
                    methodNode.SetAttribute("feature", propertyName);
                    methodNode.SetAttribute("featurevalue", "false");
                    typeNode.AppendChild(methodNode);
                }

                var fileName = Path.Combine(_intermediatePath, "Substitutions", "DependencyObjectHints.Substitutions.xml");

                Directory.CreateDirectory(Path.GetDirectoryName(fileName));

                doc.Save(fileName);
            }