2
0
Эх сурвалжийг харах

Refactor error messages into constants

Co-authored-by: tig <[email protected]>
copilot-swe-agent[bot] 3 долоо хоног өмнө
parent
commit
bf74866e81

+ 2 - 6
Terminal.Gui/App/ApplicationImpl.Lifecycle.cs

@@ -27,17 +27,13 @@ public partial class ApplicationImpl
         // If this is a legacy static instance and instance-based model was used, throw
         if (this == _instance && _modelUsage == ApplicationModelUsage.InstanceBased)
         {
-            throw new InvalidOperationException (
-                "Cannot use legacy static Application model (Application.Init/ApplicationImpl.Instance) after using modern instance-based model (Application.Create). " +
-                "Use only one model per process.");
+            throw new InvalidOperationException (ErrorLegacyAfterModern);
         }
 
         // If this is an instance-based instance and legacy static model was used, throw
         if (this != _instance && _modelUsage == ApplicationModelUsage.LegacyStatic)
         {
-            throw new InvalidOperationException (
-                "Cannot use modern instance-based model (Application.Create) after using legacy static Application model (Application.Init/ApplicationImpl.Instance). " +
-                "Use only one model per process.");
+            throw new InvalidOperationException (ErrorModernAfterLegacy);
         }
 
         if (!string.IsNullOrWhiteSpace (driverName))

+ 16 - 6
Terminal.Gui/App/ApplicationImpl.cs

@@ -26,6 +26,20 @@ public partial class ApplicationImpl : IApplication
     /// </summary>
     private static ApplicationModelUsage _modelUsage = ApplicationModelUsage.None;
 
+    /// <summary>
+    ///     Error message for when trying to use modern model after legacy static model.
+    /// </summary>
+    private const string ErrorModernAfterLegacy =
+        "Cannot use modern instance-based model (Application.Create) after using legacy static Application model (Application.Init/ApplicationImpl.Instance). " +
+        "Use only one model per process.";
+
+    /// <summary>
+    ///     Error message for when trying to use legacy static model after modern model.
+    /// </summary>
+    private const string ErrorLegacyAfterModern =
+        "Cannot use legacy static Application model (Application.Init/ApplicationImpl.Instance) after using modern instance-based model (Application.Create). " +
+        "Use only one model per process.";
+
     /// <summary>
     ///     Configures the singleton instance of <see cref="Application"/> to use the specified backend implementation.
     /// </summary>
@@ -52,9 +66,7 @@ public partial class ApplicationImpl : IApplication
             // Check if the instance-based model has already been used
             if (_modelUsage == ApplicationModelUsage.InstanceBased)
             {
-                throw new InvalidOperationException (
-                    "Cannot use legacy static Application model (Application.Init/ApplicationImpl.Instance) after using modern instance-based model (Application.Create). " +
-                    "Use only one model per process.");
+                throw new InvalidOperationException (ErrorLegacyAfterModern);
             }
 
             // Mark the usage and create the instance
@@ -72,9 +84,7 @@ public partial class ApplicationImpl : IApplication
         // Check if the legacy static model has already been initialized
         if (_modelUsage == ApplicationModelUsage.LegacyStatic && _instance?.Initialized == true)
         {
-            throw new InvalidOperationException (
-                "Cannot use modern instance-based model (Application.Create) after using legacy static Application model (Application.Init/ApplicationImpl.Instance). " +
-                "Use only one model per process.");
+            throw new InvalidOperationException (ErrorModernAfterLegacy);
         }
 
         _modelUsage = ApplicationModelUsage.InstanceBased;