System.Xml.Schema.XmlSchemaValidator.InternalValidateEndElement C# (CSharp) Method

InternalValidateEndElement() private method

private InternalValidateEndElement ( XmlSchemaInfo schemaInfo, object typedValue ) : object
schemaInfo XmlSchemaInfo
typedValue object
return object
        private object InternalValidateEndElement(XmlSchemaInfo schemaInfo, object typedValue)
        {
            if (_validationStack.Length <= 1)
            {
                throw new InvalidOperationException(SR.Format(SR.Sch_InvalidEndElementMultiple, s_methodNames[(int)ValidatorState.EndElement]));
            }
            CheckStateTransition(ValidatorState.EndElement, s_methodNames[(int)ValidatorState.EndElement]);

            SchemaElementDecl contextElementDecl = _context.ElementDecl;
            XmlSchemaSimpleType memberType = null;
            XmlSchemaType localSchemaType = null;
            XmlSchemaElement localSchemaElement = null;

            string stringValue = string.Empty;

            if (contextElementDecl != null)
            {
                if (_context.CheckRequiredAttribute && contextElementDecl.HasRequiredAttribute)
                {
                    CheckRequiredAttributes(contextElementDecl);
                }
                if (!_context.IsNill)
                {
                    if (_context.NeedValidateChildren)
                    {
                        XmlSchemaContentType contentType = contextElementDecl.ContentValidator.ContentType;
                        switch (contentType)
                        {
                            case XmlSchemaContentType.TextOnly:
                                if (typedValue == null)
                                {
                                    stringValue = _textValue.ToString();
                                    typedValue = ValidateAtomicValue(stringValue, out memberType);
                                }
                                else
                                { //Parsed object passed in, need to verify only facets
                                    typedValue = ValidateAtomicValue(typedValue, out memberType);
                                }
                                break;

                            case XmlSchemaContentType.Mixed:
                                if (contextElementDecl.DefaultValueTyped != null)
                                {
                                    if (typedValue == null)
                                    {
                                        stringValue = _textValue.ToString();
                                        typedValue = CheckMixedValueConstraint(stringValue);
                                    }
                                }
                                break;

                            case XmlSchemaContentType.ElementOnly:
                                if (typedValue != null)
                                { //Cannot pass in typedValue for complex content
                                    throw new InvalidOperationException(SR.Sch_InvalidEndElementCallTyped);
                                }
                                break;

                            default:
                                break;
                        }
                        if (!contextElementDecl.ContentValidator.CompleteValidation(_context))
                        {
                            CompleteValidationError(_context, _eventHandler, _nsResolver, _sourceUriString, _positionInfo.LineNumber, _positionInfo.LinePosition, _schemaSet);
                            _context.Validity = XmlSchemaValidity.Invalid;
                        }
                    }
                }
                // for each level in the stack, endchildren and fill value from element
                if (HasIdentityConstraints)
                {
                    XmlSchemaType xmlType = memberType == null ? contextElementDecl.SchemaType : memberType;
                    EndElementIdentityConstraints(typedValue, stringValue, xmlType.Datatype);
                }
                localSchemaType = contextElementDecl.SchemaType;
                localSchemaElement = GetSchemaElement();
            }
            if (schemaInfo != null)
            { //SET SchemaInfo
                schemaInfo.SchemaType = localSchemaType;
                schemaInfo.SchemaElement = localSchemaElement;
                schemaInfo.MemberType = memberType;
                schemaInfo.IsNil = _context.IsNill;
                schemaInfo.IsDefault = _context.IsDefault;
                if (_context.Validity == XmlSchemaValidity.NotKnown && StrictlyAssessed)
                {
                    _context.Validity = XmlSchemaValidity.Valid;
                }
                schemaInfo.Validity = _context.Validity;
            }
            Pop();
            return typedValue;
        }