Files
Akari.Prototype/Akari.Prototype.Server/Utils/IPAddressAttribute.cs
2021-06-03 14:48:02 +02:00

28 lines
616 B
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace Akari.Prototype.Server.Utils
{
public class IPAddressAttribute : ValidationAttribute
{
public IPAddressAttribute() : base("Must be a valid IP address")
{
}
public override bool IsValid(object value)
{
if (value is null)
{
return true;
}
return value is string ip && IPAddress.TryParse(ip, out _);
}
}
}