diff --git a/Material.Icons/MaterialIconDataProvider.Declaration.cs b/Material.Icons/MaterialIconDataProvider.Declaration.cs index 1a4c342..438b1ea 100644 --- a/Material.Icons/MaterialIconDataProvider.Declaration.cs +++ b/Material.Icons/MaterialIconDataProvider.Declaration.cs @@ -1,3 +1,5 @@ +using System; + namespace Material.Icons; /// ****************************************** @@ -7,16 +9,24 @@ namespace Material.Icons; /// Allows retrieving data for icons /// public partial class MaterialIconDataProvider { - private static MaterialIconDataProvider? _instance; + private static MaterialIconDataProvider _instance = new(); + /// - /// Gets the singleton instance of this provider + /// Gets or sets the singleton instance of this provider /// - public static MaterialIconDataProvider Instance => _instance ??= new MaterialIconDataProvider(); + public static MaterialIconDataProvider Instance { + get => _instance; + set { + _instance = value ?? throw new ArgumentNullException(nameof(value)); + } + } + /// /// Gets the data for the specified icon using the /// /// The icon kind /// SVG path for target icon kind + public static string GetData(MaterialIconKind kind) => Instance.ProvideData(kind); /// /// Provides the data for the specified icon kind diff --git a/build/Generators/MaterialIconDataDeclarationGenerator.cs b/build/Generators/MaterialIconDataDeclarationGenerator.cs index f132fab..4833bb1 100644 --- a/build/Generators/MaterialIconDataDeclarationGenerator.cs +++ b/build/Generators/MaterialIconDataDeclarationGenerator.cs @@ -9,8 +9,10 @@ public class MaterialIconDataDeclarationGenerator { public static void Write(AbsolutePath destinationPath) { var path = destinationPath / "MaterialIconDataProvider.Declaration.cs"; Log.Information("Writing declaration for material icons data to {Path}", path); - + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine("using System;"); + stringBuilder.AppendLine(""); stringBuilder.AppendLine("namespace Material.Icons;"); stringBuilder.AppendLine(""); stringBuilder.AppendLine("/// ******************************************"); @@ -20,16 +22,24 @@ public static void Write(AbsolutePath destinationPath) { stringBuilder.AppendLine("/// Allows retrieving data for icons"); stringBuilder.AppendLine("/// "); stringBuilder.AppendLine("public partial class MaterialIconDataProvider {"); - stringBuilder.AppendLine(" private static MaterialIconDataProvider? _instance;"); + stringBuilder.AppendLine(" private static MaterialIconDataProvider _instance = new();"); + stringBuilder.AppendLine(""); stringBuilder.AppendLine(" /// "); - stringBuilder.AppendLine(" /// Gets the singleton instance of this provider"); + stringBuilder.AppendLine(" /// Gets or sets the singleton instance of this provider"); stringBuilder.AppendLine(" /// "); - stringBuilder.AppendLine(" public static MaterialIconDataProvider Instance => _instance ??= new MaterialIconDataProvider();"); + stringBuilder.AppendLine(" public static MaterialIconDataProvider Instance {"); + stringBuilder.AppendLine(" get => _instance;"); + stringBuilder.AppendLine(" set {"); + stringBuilder.AppendLine(" _instance = value ?? throw new ArgumentNullException(nameof(value));"); + stringBuilder.AppendLine(" }"); + stringBuilder.AppendLine(" }"); + stringBuilder.AppendLine(""); stringBuilder.AppendLine(" /// "); stringBuilder.AppendLine(" /// Gets the data for the specified icon using the "); stringBuilder.AppendLine(" /// "); stringBuilder.AppendLine(" /// The icon kind"); stringBuilder.AppendLine(" /// SVG path for target icon kind"); + stringBuilder.AppendLine(""); stringBuilder.AppendLine(" public static string GetData(MaterialIconKind kind) => Instance.ProvideData(kind);"); stringBuilder.AppendLine(" /// "); stringBuilder.AppendLine(" /// Provides the data for the specified icon kind");