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)]
|
2026-11-10 01:24:43 +01:00
|
|
|
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)
|
|
|
|
|
{
|
2026-11-10 01:24:43 +01:00
|
|
|
foreach (var propertyName in propertyList)
|
2023-02-18 08:52:17 +01:00
|
|
|
{
|
2026-11-10 01:24:43 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|