StandardRuntimeEnumValidator.cs 985 B

123456789101112131415161718192021222324252627282930313233
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.ComponentModel;
  8. using System.Configuration;
  9. internal class StandardRuntimeEnumValidator : ConfigurationValidatorBase
  10. {
  11. Type enumType;
  12. public StandardRuntimeEnumValidator(Type enumType)
  13. {
  14. this.enumType = enumType;
  15. }
  16. public override bool CanValidate(Type type)
  17. {
  18. return (type.IsEnum);
  19. }
  20. public override void Validate(object value)
  21. {
  22. if (!Enum.IsDefined(enumType, value))
  23. {
  24. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException("value", (int)value, enumType));
  25. }
  26. }
  27. }
  28. }