From cab52e7a44a27fe47f4e69c6c3c5391c56d1d476 Mon Sep 17 00:00:00 2001 From: Rahul-Siemens <144675885+Rahul-Siemens@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:12:22 +0530 Subject: [PATCH] fix: add type validation for cell min/max (#27) - add type validation for cell min/max --- CHANGELOG.md | 6 ++++- .../ComponentModel/Validator/ValidatorBase.cs | 10 ++++++++ .../Data/Exceptions/Exceptions.cs | 25 ++++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69ca6a9..06c6a21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ # SourceGrid -## [3.0.0] - 2024-01-18 +## [3.0.0] - 2024-01-29 ### Major Changes - Migrate to .net 8.0 related to #3 - Deprecated DevAge Serialization +### Fixed + +- Fixed bug in validator base related to #25 + ## [2.0.0] - 2023-11-24 ### Major Changes diff --git a/Src/DevAgeSourcePack4/ComponentModel/Validator/ValidatorBase.cs b/Src/DevAgeSourcePack4/ComponentModel/Validator/ValidatorBase.cs index da07b40..93db36c 100644 --- a/Src/DevAgeSourcePack4/ComponentModel/Validator/ValidatorBase.cs +++ b/Src/DevAgeSourcePack4/ComponentModel/Validator/ValidatorBase.cs @@ -498,6 +498,11 @@ public object MinimumValue if (m_MinimumValue != value) { m_MinimumValue = value; + + if (m_MinimumValue.GetType() != ValueType) + { + throw new ValidationErrorException(ValueTypeName, ObjectToStringForError(m_MinimumValue)); + } OnChanged(EventArgs.Empty); } } @@ -515,6 +520,11 @@ public object MaximumValue if (m_MaximumValue != value) { m_MaximumValue = value; + + if (m_MaximumValue.GetType() != ValueType) + { + throw new ValidationErrorException(ValueTypeName, ObjectToStringForError(m_MaximumValue)); + } OnChanged(EventArgs.Empty); } } diff --git a/Src/DevAgeSourcePack4/Data/Exceptions/Exceptions.cs b/Src/DevAgeSourcePack4/Data/Exceptions/Exceptions.cs index 2d9488e..dfa819a 100644 --- a/Src/DevAgeSourcePack4/Data/Exceptions/Exceptions.cs +++ b/Src/DevAgeSourcePack4/Data/Exceptions/Exceptions.cs @@ -127,10 +127,27 @@ public ConversionErrorException(string destinationType, string value, Exception } } - /// - /// Common EventArgs class used to store and raise events with an Exception associated - /// - public class ExceptionEventArgs : EventArgs + /// + /// Validation exception + /// + [Serializable] + public class ValidationErrorException : DevAgeApplicationException + { + /// + /// Constructor + /// + /// + /// + public ValidationErrorException(string type, string value) : + base(value + " is not of type " + type + ".") + { + } + } + + /// + /// Common EventArgs class used to store and raise events with an Exception associated + /// + public class ExceptionEventArgs : EventArgs { /// /// Constructor