Created
March 5, 2021 08:57
-
-
Save xrisdoc/fcb79151c633e328b5bf46aa3f26998d to your computer and use it in GitHub Desktop.
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
using System; | |
using System.ComponentModel.DataAnnotations; | |
namespace ADL.TechPubs.WebFramework.Attributes | |
{ | |
public class IsTrueAttribute : ValidationAttribute | |
{ | |
/// <summary> | |
/// Determines whether the specified value of the object is valid. | |
/// </summary> | |
/// <returns> | |
/// true if the specified value is valid; otherwise, false. | |
/// </returns> | |
/// <param name="value">The value of the specified validation object on which the <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute"/> is declared.</param> | |
public override bool IsValid(object value) | |
{ | |
if (value == null) return false; | |
if (value.GetType() != typeof(bool)) throw new InvalidOperationException("can only be used on boolean properties."); | |
return (bool)value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment