/// <inheritdoc/> // Called by the base class to write the start of the file (i.e. everything up to the body of the Instantiator class). protected override void WriteFileStart(CodeBuilder builder) { // A sorted set to hold the namespaces that the generated code will use. The set is maintained in sorted order. var namespaces = new SortedSet <string>(); if (Info.UsesCanvas) { namespaces.Add("Microsoft.Graphics.Canvas"); } if (Info.UsesCanvasEffects) { namespaces.Add("Microsoft.Graphics.Canvas.Effects"); } if (Info.UsesCanvasGeometry) { // Windows.Graphics is needed for IGeometrySource2D. namespaces.Add("Windows.Graphics"); namespaces.Add("Microsoft.Graphics.Canvas.Geometry"); } if (Info.UsesNamespaceWindowsUIXamlMedia) { namespaces.Add("System.ComponentModel"); namespaces.Add("System.Runtime.InteropServices.WindowsRuntime"); namespaces.Add("Windows.Foundation"); namespaces.Add($"{_winUiNamespace}.Xaml.Media"); } if (Info.GenerateDependencyObject) { namespaces.Add($"{_winUiNamespace}.Xaml"); } if (Info.UsesStreams) { namespaces.Add("System.IO"); } namespaces.Add("System"); namespaces.Add("System.Numerics"); // Windows.UI is needed for Color. namespaces.Add("Windows.UI"); namespaces.Add($"{_winUiNamespace}.Composition"); // Write out each namespace using. foreach (var n in namespaces) { builder.WriteLine($"using {n};"); } builder.WriteLine(); builder.WriteLine($"namespace {Info.Namespace}"); builder.OpenScope(); // Write a description of the source as comments. builder.WritePreformattedCommentLines(GetSourceDescriptionLines()); // If the composition has LoadedImageSurface, write a class that implements the IDynamicAnimatedVisualSource interface. // Otherwise, implement the IAnimatedVisualSource interface. if (Info.LoadedImageSurfaces.Count > 0) { WriteIDynamicAnimatedVisualSource(builder); } else { WriteIAnimatedVisualSource(builder); } builder.CloseScope(); builder.WriteLine(); }