System.Xml.Xsl.XmlQueryTypeFactory.AttributesOf C# (CSharp) Method

AttributesOf() public method

For the type of node sequence calculate type of attributes filtered with a type (filter)
public AttributesOf ( XmlQueryType source, XmlQueryType filter ) : XmlQueryType
source XmlQueryType source type
filter XmlQueryType type filter
return XmlQueryType
        public XmlQueryType AttributesOf(XmlQueryType source, XmlQueryType filter) {
            Debug.Assert(filter.IsNode && filter.Count == 1 && filter.IsSingleton);
            List<XmlQueryType> list = new List<XmlQueryType>();
            XmlQueryCardinality card = XmlQueryCardinality.None;

            foreach (XmlQueryType sourceItem in source) {
                switch (sourceItem.TypeCode) {
                case XmlTypeCode.Node:
                case XmlTypeCode.Element:
                    XmlSchemaType sourceSchemaType = sourceItem.SchemaType;
                    if (sourceSchemaType == XmlSchemaComplexType.UntypedAnyType) {
                        // attfibutes of of xdt:untypedAny are attribute(*, xdt:untypedAtomic)*
                        card |= AddFilteredPrime(list, UntypedAttribute, filter) * XmlQueryCardinality.ZeroOrOne;
                    }
                    else {
                        // Only complex type can have attributes
                        XmlSchemaComplexType type = sourceSchemaType as XmlSchemaComplexType;
                        if (type != null) {
                            card |= AddAttributes(list, type.AttributeUses, type.AttributeWildcard, filter);
                        }
                    }
                    break;

                case XmlTypeCode.Document:
                case XmlTypeCode.Attribute:
                case XmlTypeCode.ProcessingInstruction:
                case XmlTypeCode.Comment:
                case XmlTypeCode.Namespace:
                case XmlTypeCode.Text:
                    card |= XmlQueryCardinality.Zero;
                    break;

                default:
                    Debug.Assert(sourceItem.IsAtomicValue, "missed case for a node");
                    return null;
                }
            }
            // Make sure that cardinality is at least Zero
            return PrimeProduct(ChoiceType.Create(list), source.Cardinality * card);
        }