Click here to Skip to main content
12,821,084 members (33,592 online)
Click here to Skip to main content


44 bookmarked
Posted 6 Sep 2005

Parser Schemas– Easy and Powerful parsing of XML-based languages

, 18 Oct 2005
An article on parsing XML files according to the specified schema.
 * Comnicate.CodeDom.Xml.ParserSchemas                                 *
 * Parses xml-based languages according to a user defined schema.      *
 * Copyright � 2005 Tomas Deml (as Comnicate!)                         *
 *                                          *
 *                                                                     *
 * This library is free software; you can redistribute it and/or       *
 * modify it under the terms of the GNU Lesser General Public          *
 * License as published by the Free Software Foundation; either        *
 * version 2.1 of the License, or (at your option) any later version.  *
 *                                                                     *
 * This library is distributed in the hope that it will be useful,     *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of      *
 * Lesser General Public License for more details.                     *

using System;
using System.Collections.Generic;
using System.Text;

namespace Comnicate.CodeDom.Xml.ParserSchemas.Rules.Evaluation.PrimitiveValueValidators
    /// <summary>
    /// Validates enum values.
    /// </summary>
    public sealed class EnumValueValidator : IValueValidator
        #region Fields

        private Type EnumType;


        #region .ctors, properties & methods

        /// <summary>
        /// Initializes a new instance of the <see cref="EnumValueValidator"/> class.
        /// </summary>
        private EnumValueValidator() { }

        /// <summary>
        /// Creates the validator for a specific enum type.
        /// </summary>
        public static IValueValidator Create(Type enumType)
            // Null?
            if (enumType == null) throw new ArgumentNullException("enumType");

            // Create specific instance
            EnumValueValidator validator = new EnumValueValidator();
            validator.EnumType = enumType;

            // Return
            return validator;

        #region IValueValidator Members

        /// <summary>
        /// Validates the enum value.
        /// </summary>
        /// <param name="value">Enum value.</param>
        /// <param name="matchingRule">Rule to validate.</param>
        /// <returns>True if valid; false if invalid.</returns>
        public bool IsValidValue(string value, ValidatingNonParentalRule matchingRule)
            return Enum.IsDefined(this.EnumType, value);



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Tomas Deml
Czech Republic Czech Republic
I'm a student of the Low-voltage Electrical Engineering specialized on Computing from the Czech republic.

I'm a C# kind of guy, fan of .NET.

I've formed a programming group called 'Comnicate!'. Currently the only member of the group is myself. Wink | ;-)

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 18 Oct 2005
Article Copyright 2005 by Tomas Deml
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid