Property Comparison Validator

Topics: Validation Application Block
Oct 15, 2008 at 8:28 AM
How do I validate a decimal value that should be greater than 0.01?
Oct 15, 2008 at 10:22 AM
Hi,

you can try this.

--- Sample Class

    public class AuctionItem
    {
        private double amount = 0.00;
        private double compare = 0.01;
        [PropertyComparisonValidator("CompareProperty", ComparisonOperator.GreaterThan)]
        public double Amount
        {
            get
            {
                return amount;
            }
        }

        public double CompareProperty
        {
            get
            {
                return compare;
            }
        }

    }


To Invoke
-----

static void Main(string[] args)
        {
            AuctionItem s = new AuctionItem();
            ValidationResults res = Validation.Validate<Samp.AuctionItem>(s);
            if (res.IsValid)
            {
                Console.WriteLine("Greater than 0.01");
            }
            else
            {
                Console.WriteLine("Less than 0.01, Not valid!");
            }
            Console.ReadLine();
        }


Hope this helps.


.Kratos

Oct 15, 2008 at 10:24 AM
Edited Oct 15, 2008 at 10:24 AM
Hi,

Also try this links.

http://msdn.microsoft.com/en-us/library/cc309346.aspx
http://davidhayden.com/blog/dave/archive/2007/03/02/PropertyComparisonValidatorValidationApplicationBlock.aspx


.Kratos
Oct 15, 2008 at 11:07 AM
thanks.