示例#1
0
        private void VisitElements(IEnumerable model, VisitContext visitContext)
        {
            Contract.Requires(model != null);
            Contract.Requires(visitContext != null);

            Type          elementType     = this.GetElementType(model.GetType());
            ModelMetadata elementMetadata = visitContext.MetadataProvider.GetMetadataForType(null, elementType);

            ElementScope elementScope = new ElementScope {
                Index = 0
            };

            visitContext.KeyBuilders.Push(elementScope);
            foreach (object element in model)
            {
                elementMetadata.Model = element;
                this.VisitNodeAndChildren(elementMetadata, visitContext);

                elementScope.Index++;
            }

            visitContext.KeyBuilders.Pop();
        }
示例#2
0
        private void VisitElements(IEnumerable model, VisitContext visitContext)
        {
            Contract.Requires(model != null);
            Contract.Requires(visitContext != null);

            Type elementType = this.GetElementType(model.GetType());
            ModelMetadata elementMetadata = visitContext.MetadataProvider.GetMetadataForType(null, elementType);

            ElementScope elementScope = new ElementScope { Index = 0 };
            visitContext.KeyBuilders.Push(elementScope);
            foreach (object element in model)
            {
                elementMetadata.Model = element;
                this.VisitNodeAndChildren(elementMetadata, visitContext);

                elementScope.Index++;
            }

            visitContext.KeyBuilders.Pop();
        }
示例#3
0
        private bool ValidateElements(IEnumerable model, ValidationContext validationContext)
        {
            Contract.Requires(model != null);
            Contract.Requires(validationContext != null);

            bool isValid = true;
            Type elementType = this.GetElementType(model.GetType());
            ModelMetadata elementMetadata = validationContext.MetadataProvider.GetMetadataForType(null, elementType);

            ElementScope elementScope = new ElementScope { Index = 0 };
            validationContext.KeyBuilders.Push(elementScope);
            foreach (object element in model)
            {
                elementMetadata.Model = element;
                if (!this.ValidateNodeAndChildren(elementMetadata, validationContext, model))
                {
                    isValid = false;
                }

                elementScope.Index++;
            }

            validationContext.KeyBuilders.Pop();
            return isValid;
        }