Add global usings (#668)

* Use global usings

* Fix namespace declarations for test projects
This commit is contained in:
Patrik Svensson
2021-12-23 16:50:31 +01:00
committed by GitHub
parent eb6a9d8d04
commit 52c1d9122b
514 changed files with 10659 additions and 12441 deletions

View File

@ -1,29 +1,25 @@
using System;
using Spectre.Console.Cli;
namespace Spectre.Console.Tests.Data;
namespace Spectre.Console.Tests.Data
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class EvenNumberValidatorAttribute : ParameterValidationAttribute
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class EvenNumberValidatorAttribute : ParameterValidationAttribute
public EvenNumberValidatorAttribute(string errorMessage)
: base(errorMessage)
{
public EvenNumberValidatorAttribute(string errorMessage)
: base(errorMessage)
{
}
}
public override ValidationResult Validate(CommandParameterContext context)
public override ValidationResult Validate(CommandParameterContext context)
{
if (context.Value is int integer)
{
if (context.Value is int integer)
if (integer % 2 == 0)
{
if (integer % 2 == 0)
{
return ValidationResult.Success();
}
return ValidationResult.Error($"Number is not even ({context.Parameter.PropertyName}).");
return ValidationResult.Success();
}
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
return ValidationResult.Error($"Number is not even ({context.Parameter.PropertyName}).");
}
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
}
}
}

View File

@ -1,29 +1,25 @@
using System;
using Spectre.Console.Cli;
namespace Spectre.Console.Tests.Data;
namespace Spectre.Console.Tests.Data
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class PositiveNumberValidatorAttribute : ParameterValidationAttribute
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class PositiveNumberValidatorAttribute : ParameterValidationAttribute
public PositiveNumberValidatorAttribute(string errorMessage)
: base(errorMessage)
{
public PositiveNumberValidatorAttribute(string errorMessage)
: base(errorMessage)
{
}
}
public override ValidationResult Validate(CommandParameterContext context)
public override ValidationResult Validate(CommandParameterContext context)
{
if (context.Value is int integer)
{
if (context.Value is int integer)
if (integer > 0)
{
if (integer > 0)
{
return ValidationResult.Success();
}
return ValidationResult.Error($"Number is not greater than 0 ({context.Parameter.PropertyName}).");
return ValidationResult.Success();
}
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
return ValidationResult.Error($"Number is not greater than 0 ({context.Parameter.PropertyName}).");
}
throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName}).");
}
}
}