protected override IValidationError[] IsValidSnapshot(object values, IContextEntry[] context)
        {
            if (values is IEnumerable enumerable)
            {
                IList <object> list = new List <object>();

                foreach (var item in enumerable)
                {
                    list.Add(item);
                }

                var errors = list.Select((value, index) => SubType.Validate(value, StateTreeUtils.GetContextForPath(context, $"{index}", SubType)));

                return(errors.Aggregate(Array.Empty <IValidationError>(), (acc, value) => acc.Concat(value).ToArray()));
            }

            return(new IValidationError[]
            {
                new ValidationError
                {
                    Context = context,

                    Value = values,

                    Message = $"Value is not an array or list or enumerable"
                }
            });
        }
Exemplo n.º 2
0
        protected override IValidationError[] IsValidSnapshot(object values, IContextEntry[] context)
        {
            if (values is IDictionary <object, object> dictionary)
            {
                var errors = dictionary.Keys.Select(key => SubType.Validate(dictionary[key], StateTreeUtils.GetContextForPath(context, $"{key}", SubType)));

                return(errors.Aggregate(new IValidationError[] { }, (acc, value) => acc.Concat(value).ToArray()));
            }

            return(new IValidationError[]
            {
                new ValidationError
                {
                    Context = context,

                    Value = values,

                    Message = $"Value is not an dictionary"
                }
            });
        }