internal void CategorizePropEntries()
        {
            if (Children.Count > 0)
            {
                GridEntry[] childEntries = new GridEntry[this.Children.Count];
                this.Children.CopyTo(childEntries, 0);

                if ((this.PropertySort & PropertySort.Categorized) != 0)
                {
                    // first, walk through all the entires and
                    // group them by their category by adding
                    // them to a hashtable of arraylists.
                    //
                    Hashtable bins = new Hashtable();
                    for (int i = 0; i < childEntries.Length; i++)
                    {
                        GridEntry pe = childEntries[i];
                        Debug.Assert(pe != null);
                        if (pe != null)
                        {
                            string    category = pe.PropertyCategory;
                            ArrayList bin      = (ArrayList)bins[category];
                            if (bin == null)
                            {
                                bin            = new ArrayList();
                                bins[category] = bin;
                            }
                            bin.Add(pe);
                        }
                    }

                    // now walk through the hashtable
                    // and create a categorygridentry for each
                    // category that holds all the properties
                    // of that category.
                    //
                    ArrayList             propList = new ArrayList();
                    IDictionaryEnumerator enumBins = (IDictionaryEnumerator)bins.GetEnumerator();
                    while (enumBins.MoveNext())
                    {
                        ArrayList bin = (ArrayList)enumBins.Value;
                        if (bin != null)
                        {
                            string category = (string)enumBins.Key;
                            if (bin.Count > 0)
                            {
                                GridEntry[] rgpes = new GridEntry[bin.Count];
                                bin.CopyTo(rgpes, 0);
                                try {
                                    propList.Add(new CategoryGridEntry(this.ownerGrid, this, category, rgpes));
                                }
                                catch {
                                }
                            }
                        }
                    }

                    childEntries = new GridEntry[propList.Count];
                    propList.CopyTo(childEntries, 0);
                    StringSorter.Sort(childEntries);

                    ChildCollection.Clear();
                    ChildCollection.AddRange(childEntries);
                }
            }
        }
示例#2
0
 public virtual bool ParseChildren(ChildCollection c)
 {
     Contract.Assume(c.Parser == this);
     c.Clear();
     var res = true;
     var cl = CurrentToken.Class;
     while (cl != TokenClass.EndOfDocument &&
         (cl == TokenClass.Literal || cl == TokenClass.Identifier || cl == TokenClass.Equals || cl == TokenClass.CDataStart || cl == TokenClass.String || cl == TokenClass.TagStart ||
             cl == TokenClass.ServerTagStart || cl == TokenClass.DoctypeStart || cl == TokenClass.XmlDocTagStart)) {
         switch (cl) {
         case TokenClass.Identifier:
         case TokenClass.Literal:
         case TokenClass.Equals:
         case TokenClass.CDataStart:
         case TokenClass.String:
             var literal = c.New<Literal>();
             if (!ParseLiteral(literal, true)) res = false;
             break;
         case TokenClass.TagStart:
             var p = PeekToken();
             if (p.Class == TokenClass.Identifier && p.Value.ToLower() == "script") {
                 var script = c.New<Script>();
                 if (!ParseScript(script)) res = false;
             } else if (p.Class == TokenClass.Identifier && p.Value.ToLower() == "style") {
                 var style = c.New<Style>();
                 if (!ParseStyle(style)) res = false;
             } else {
                 var elem = c.New<Element>();
                 if (!ParseElement(elem)) res = false;
             }
             break;
         case TokenClass.ServerTagStart:
             if (CurrentToken.ServerTagClass == ServerTagClass.PersistentObject) {
                 var t = c.New<PersistentObject>();
                 if (!ParsePersistentObject(t)) res = false;
             } else {
                 var serverTag = c.New<ServerTag>();
                 if (!ParseServerTag(serverTag)) res = false;
             }
             break;
         case TokenClass.DoctypeStart:
             var doctype = c.New<Doctype>();
             if (!ParseDoctype(doctype)) res = false;
             break;
         case TokenClass.XmlDocTagStart:
             var xmldoc = c.New<XmlDocHeader>();
             if (!ParseXmlDocHeader(xmldoc)) res = false;
             break;
         }
         cl = CurrentToken.Class;
     }
     return res;
 }