Files
SocialPub/PrivaPub.ClientModels/AtLeastOnePropertyAttribute.cs
T

29 lines
611 B
C#
Raw Permalink Normal View History

2023-02-18 08:52:17 +01:00
using System.ComponentModel.DataAnnotations;
2023-02-19 00:43:43 +01:00
namespace PrivaPub.ClientModels
2023-02-18 08:52:17 +01:00
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class AtLeastOnePropertyAttribute(params string[] propertyList) : ValidationAttribute
2023-02-18 08:52:17 +01:00
{
public override object TypeId
{
get
{
return this;
}
}
public override bool IsValid(object value)
{
foreach (var propertyName in propertyList)
2023-02-18 08:52:17 +01:00
{
var propertyInfo = value.GetType().GetProperty(propertyName);
2023-02-18 08:52:17 +01:00
if (propertyInfo != null && propertyInfo.GetValue(value, null) != null)
return true;
}
return false;
}
}
}