This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/apis-rework' into apis-rework
- Loading branch information
Showing
35 changed files
with
1,648 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Exiled.API/Features/Attributes/Validators/GreaterThanAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="GreaterThanAttribute.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Attributes.Validators | ||
{ | ||
using System; | ||
|
||
using Exiled.API.Interfaces; | ||
|
||
/// <summary> | ||
/// An attribute that validates if the value of the marked property is greater than a specified number. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public sealed class GreaterThanAttribute : Attribute, IValidator | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GreaterThanAttribute"/> class. | ||
/// </summary> | ||
/// <param name="number">The number the marked property should be greater than.</param> | ||
/// <param name="isIncluded">Whether or not the comparison in inclusive (includes <see cref="Number"/> as a valid value for the marked property).</param> | ||
public GreaterThanAttribute(object number, bool isIncluded = false) | ||
{ | ||
Number = (IComparable)number; | ||
IsIncluded = isIncluded; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the number that the value of the marked property should be greater than. | ||
/// </summary> | ||
public IComparable Number { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether or not the comparison is inclusive. | ||
/// <remarks>If this returns true, <see cref="Number"/> is a valid value for the marked property.</remarks> | ||
/// </summary> | ||
public bool IsIncluded { get; } | ||
|
||
/// <inheritdoc/> | ||
public bool Validate(object value) => Number.CompareTo(value) is -1 || (IsIncluded && Number.CompareTo(value) is 0); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Exiled.API/Features/Attributes/Validators/LessThanAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="LessThanAttribute.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Attributes.Validators | ||
{ | ||
using System; | ||
|
||
using Exiled.API.Interfaces; | ||
|
||
/// <summary> | ||
/// An attribute that validates if the value of the marked property is less than a specified number. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public sealed class LessThanAttribute : Attribute, IValidator | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LessThanAttribute"/> class. | ||
/// </summary> | ||
/// <param name="number">The number the marked property should be less than.</param> | ||
/// <param name="isIncluded">Whether or not the comparison in inclusive (includes <see cref="Number"/> as a valid value for the marked property).</param> | ||
public LessThanAttribute(object number, bool isIncluded = false) | ||
{ | ||
Number = (IComparable)number; | ||
IsIncluded = isIncluded; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the number that the value of the marked property should be less than. | ||
/// </summary> | ||
public IComparable Number { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether or not the comparison is inclusive. | ||
/// <remarks>If this returns true, <see cref="Number"/> is a valid value for the marked property.</remarks> | ||
/// </summary> | ||
public bool IsIncluded { get; } | ||
|
||
/// <inheritdoc/> | ||
public bool Validate(object value) => Number.CompareTo(value) is 1 || (IsIncluded && Number.CompareTo(value) is 0); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Exiled.API/Features/Attributes/Validators/NonNegativeAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="NonNegativeAttribute.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Attributes.Validators | ||
{ | ||
using System; | ||
|
||
using Exiled.API.Interfaces; | ||
|
||
/// <summary> | ||
/// An attribute that validates if the value of the marked property is non-negative. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public sealed class NonNegativeAttribute : Attribute, IValidator | ||
{ | ||
/// <inheritdoc/> | ||
public bool Validate(object value) => value is >= 0; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Exiled.API/Features/Attributes/Validators/NonPositiveAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="NonPositiveAttribute.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Attributes.Validators | ||
{ | ||
using System; | ||
|
||
using Exiled.API.Interfaces; | ||
|
||
/// <summary> | ||
/// An attribute that validates if the value of the marked property is non-positive. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public sealed class NonPositiveAttribute : Attribute, IValidator | ||
{ | ||
/// <inheritdoc/> | ||
public bool Validate(object value) => value is <= 0; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Exiled.API/Features/Attributes/Validators/PossibleValuesAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="PossibleValuesAttribute.cs" company="Exiled Team"> | ||
// Copyright (c) Exiled Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Attributes.Validators | ||
{ | ||
using System; | ||
|
||
using Exiled.API.Interfaces; | ||
|
||
/// <summary> | ||
/// An attribute that validates if the value of the marked property included in the specified values. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public sealed class PossibleValuesAttribute : Attribute, IValidator | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PossibleValuesAttribute"/> class. | ||
/// </summary> | ||
/// <param name="values">The values the marked property can have that should be considered valid.</param> | ||
public PossibleValuesAttribute(params object[] values) | ||
{ | ||
Values = values; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the values the marked property can have that should be considered valid. | ||
/// </summary> | ||
public object[] Values { get; } | ||
|
||
/// <inheritdoc/> | ||
public bool Validate(object value) => Values.Contains(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.