示例#1
0
        private static (List <Validation>, Dictionary <string, List <Validation> >) Validate
        (
            StructureInstance <TStructure> structure,
            TStructure value,
            CancellationToken token
        )
        {
            token.ThrowIfCancellationRequested();

            var structureValidations = new List <Validation>();
            var memberValidations    = new Dictionary <string, List <Validation> >();

            if (structure.Structure.Validator != null)
            {
                structureValidations = structure.Structure.Validator.Invoke(structure.Structure, value);
            }

            token.ThrowIfCancellationRequested();

            foreach (IMemberInstance <TStructure> member in structure.AllMemberInstances())
            {
                token.ThrowIfCancellationRequested();

                List <Validation>?validations = member.Validations(value);
                if (validations == null)
                {
                    continue;
                }

                token.ThrowIfCancellationRequested();

                if (!memberValidations.ContainsKey(member.ID))
                {
                    memberValidations[member.ID] = new List <Validation>();
                }

                memberValidations[member.ID].AddRange(validations);
            }

            return(structureValidations, memberValidations);
        }
示例#2
0
 public ValidationState(StructureInstance <TStructure> structureInstance)
 {
     _structureInstance = structureInstance;
 }