Bind.XmlSpecReader.ReadEnums C# (CSharp) Method

ReadEnums() private method

private ReadEnums ( XPathNavigator nav ) : EnumCollection
nav System.Xml.XPath.XPathNavigator
return EnumCollection
        private EnumCollection ReadEnums(XPathNavigator nav)
        {
            EnumCollection enums = new EnumCollection();
            Enum all = new Enum() { Name = Settings.CompleteEnumName };

            if (nav != null)
            {
                foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty))
                {
                    Enum e = new Enum()
                    {
                        Name = node.GetAttribute("name", String.Empty),
                        Type = node.GetAttribute("type", String.Empty)
                    };
                    if (String.IsNullOrEmpty(e.Name))
                        throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString()));

                    foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
                    {
                        Constant c = null;
                        switch (param.Name)
                        {
                            case "token":
                                c = new Constant
                                {
                                    Name = param.GetAttribute("name", String.Empty),
                                    Value = param.GetAttribute("value", String.Empty)
                                };
                                break;

                            case "use":
                                c = new Constant
                                {
                                    Name = param.GetAttribute("token", String.Empty),
                                    Reference = param.GetAttribute("enum", String.Empty),
                                    Value = param.GetAttribute("token", String.Empty),
                                };
                                break;

                            default:
                                throw new NotSupportedException();
                        }
                        Utilities.Merge(all, c);
                        try
                        {
                            if (!e.ConstantCollection.ContainsKey(c.Name))
                            {
                                e.ConstantCollection.Add(c.Name, c);
                            }
                            else if (e.ConstantCollection[c.Name].Value != c.Value)
                            {
                                var existing = e.ConstantCollection[c.Name];
                                if (existing.Reference != null && c.Reference == null)
                                {
                                    e.ConstantCollection[c.Name] = c;
                                }
                                else if (existing.Reference == null && c.Reference != null)
                                {
                                    // Keep existing
                                }
                                else
                                {
                                    Console.WriteLine("[Warning] Conflicting token {0}.{1} with value {2} != {3}",
                                        e.Name, c.Name, e.ConstantCollection[c.Name].Value, c.Value);
                                }
                            }
                        }
                        catch (ArgumentException ex)
                        {
                            Console.WriteLine("[Warning] Failed to add constant {0} to enum {1}: {2}", c.Name, e.Name, ex.Message);
                        }
                    }

                    Utilities.Merge(enums, e);
                }
            }

            Utilities.Merge(enums, all);
            return enums;
        }

Same methods

XmlSpecReader::ReadEnums ( string file, EnumCollection enums ) : void