Template10 icon indicating copy to clipboard operation
Template10 copied to clipboard

Template10-Validatation ValidatableModelBase question

Open blhussey opened this issue 10 years ago • 1 comments

What is the point of the validating on the write method as well as validating on the properties changed event. Am I missing a use case for validating twice?

public ValidatableModelBase()
        {
            Properties.MapChanged += (s, e) =>
            {
                if (e.CollectionChange.Equals(CollectionChange.ItemInserted))
                    Properties[e.Key].ValueChanged += (sender, args) =>
                    {
                        RaisePropertyChanged(e.Key);
                        Validate();
                        RaisePropertyChanged(nameof(IsDirty));
                        RaisePropertyChanged(nameof(IsValid));
                    };
            };
        }

protected void Write<T>(T value, [CallerMemberName]string propertyName = null, bool validateAfter = true)
        {
            if (!Properties.ContainsKey(propertyName))
                Properties.Add(propertyName, new Property<T>());
            var property = (Properties[propertyName] as IProperty<T>);
            var previous = property.Value;
            if (!property.IsOriginalSet || !Equals(value, previous))
            {
                property.Value = value;
                if (validateAfter) Validate();
            }
        }

blhussey avatar Oct 13 '16 15:10 blhussey

Hmm. That does feel a little overkill.

JerryNixon avatar Oct 19 '16 14:10 JerryNixon