Esempio n. 1
0
        public NamespaceDefinition(MetaDefinition metaDef, XmlElement elem)
        {
            MetaDef = metaDef;

            // The child namespace names are stored in the attributes "second" and "third". Thus
            // we can only support up to three namespace levels (like "Level1::Level2::Level3").
            string second = elem.GetAttribute("second");
            string third  = elem.GetAttribute("third");

            NativeName = elem.GetAttribute("name");
            CLRName    = metaDef.ManagedNamespace;

            if (second != "")
            {
                NativeName += "::" + second;
                CLRName    += "::" + second;
            }

            if (third != "")
            {
                NativeName += "::" + third;
                CLRName    += "::" + third;
            }

            // If this is a child namespace, set parent and add itself to the parent.
            if (NativeName.Contains("::"))
            {
                // Is a child namespace.
                string parentNamespaceName = NativeName.Substring(0, NativeName.LastIndexOf("::"));
                ParentNamespace = metaDef.GetNameSpace(parentNamespaceName);

                ParentNamespace._childNamespaces.Add(this);
            }
            else
            {
                ParentNamespace = null;
            }

            //
            // Add types contained in this namespace.
            //
            foreach (XmlElement child in elem.ChildNodes)
            {
                AbstractTypeDefinition type = MetaDef.Factory.CreateType(this, null, child);
                if (type != null)
                {
                    _containedTypes.Add(type);
                }
            }
        }