Stores property information for code generation
コード例 #1
0
        private void ParseStartElements(XmlTextReader reader, Dictionary<string, ClassInfo> table, ParentInfo parent, XmlNamespaceManager nps, string className)
        {
            if (stack.Count != 0)
            {
                ////Get the parent
                parent = stack.Peek();

                ////Get the child element from inside the parent
                if (parent.ChildCount.ContainsKey(className))
                {
                    ////increment the Occurrence of the child element inside the parent
                    int childCount = parent.ChildCount[className];
                    parent.ChildCount[className] = ++childCount;
                }
                else
                {
                    ////if child does not exist in the parent add it with Occurrence = 1
                    parent.ChildCount.Add(className, 1);
                }
            }

            if (!reader.IsEmptyElement)
            {
                ////If its not an empty element push it in the stack which
                ////contains all parent elements
                stack.Push(new ParentInfo());
            }

            ClassInfo classInfo;

            if (!table.TryGetValue(className, out classInfo))
            {
                ////Create a ClassInfo every time we hit an element and it is not already
                ////contained in the global table.
                classInfo = new ClassInfo(className);
                table.Add(className, classInfo);
            }

            if (reader.LocalName != reader.Name)
            {
                string lookupName = reader.Prefix == "xmlns" ? reader.LocalName : reader.Prefix;
                classInfo.Namespace = nps.LookupNamespace(lookupName);
            }

            ////Add any new attributes that are not already defined in the classInfo....
            for (int index = 0; index < reader.AttributeCount; index++)
            {
                reader.MoveToAttribute(index);
                string localName = reader.LocalName;
                if (!classInfo.Properties.ContainsKey(localName) && (!reader.Name.StartsWith("xmlns")))
                {
                    PropertyInfo propertyInfo = new PropertyInfo(localName, true);
                    classInfo.Properties[propertyInfo.Name] = propertyInfo;
                }
            }
        }
コード例 #2
0
        private void ParseEndElements(Dictionary<string, ClassInfo> table, string className)
        {
            ParentInfo parent = stack.Pop();
            ClassInfo classInfo = table[className];
            Dictionary<string, PropertyInfo> classMembers = classInfo.Properties;

            foreach (KeyValuePair<string, int> child in parent.ChildCount)
            {
                string childName = child.Key;
                int childCount = child.Value;
                int existingChildCount = 0;

                if (classMembers.ContainsKey(childName))
                {
                    existingChildCount = classMembers[childName].Occurrences;
                }
                else
                {
                    PropertyInfo property = new PropertyInfo(childName, false);
                    classMembers[childName] = property;
                }

                if (childCount > existingChildCount)
                {
                    classMembers[childName].Occurrences = childCount;
                }
            }
        }