Example #1
0
        public void GenerateRegisterBodyCode(GeneratorExecutionContext context, StringBuilder sourceBuilder)
        {
            foreach (var file in context.AdditionalFiles)
            {
                var extension = Path.GetExtension(file.Path);

                if (extension.Equals(".ttf", StringComparison.InvariantCultureIgnoreCase) ||
                    extension.Equals(".otf", StringComparison.InvariantCultureIgnoreCase))
                {
                    var alias = context.GetMSBuildItemMetadata(file, "FontAlias");

                    var filename = Path.GetFileName(file.Path);

                    var srcAlias = string.IsNullOrWhiteSpace(alias) ? "null" : $"\"{alias}\"";

                    sourceBuilder.AppendLine(
                        @"global::Xamarin.Forms.Internals.FontRegistrar.Register(
                            new global::Xamarin.Forms.ExportFontAttribute(""" + filename + @""")
                            { Alias = " + srcAlias + @" },
                            global::System.Reflection.Assembly.GetExecutingAssembly());");
                }
            }
        }