mirror of
https://github.com/bitwarden/server
synced 2025-12-06 00:03:34 +00:00
30 lines
677 B
C#
30 lines
677 B
C#
// FIXME: Update this file to be null safe and then delete the line below
|
|
#nullable disable
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace Bit.Api.Utilities;
|
|
|
|
public class EnumMatchesAttribute<T>(params T[] accepted) : ValidationAttribute
|
|
where T : Enum
|
|
{
|
|
public override bool IsValid(object value)
|
|
{
|
|
if (value == null || accepted == null || accepted.Length == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var success = Enum.TryParse(typeof(T), value.ToString(), out var result);
|
|
|
|
if (!success)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var typed = (T)result;
|
|
|
|
return accepted.Contains(typed);
|
|
}
|
|
}
|