mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Refactor error messages into constants
Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user