public void Add(MetadataTables tables)
        {
            ContractUtils.Requires(tables != null);

            foreach (TypeDef typeDef in tables.TypeDefs)
            {
                if (typeDef.IsGlobal || typeDef.Attributes.IsNested())
                {
                    continue;
                }

                MetadataNamePart  prefix = typeDef.Namespace.GetExtent();
                NamespaceTreeNode ns     = null;

                while (true)
                {
                    NamespaceTreeNode existing;
                    if (_names.TryGetValue(prefix, out existing))
                    {
                        if (ns == null)
                        {
                            existing.AddType(typeDef);
                        }
                        else
                        {
                            existing.AddNamespace(ns);
                        }
                        break;
                    }


                    ContractUtils.Assert(prefix.Length > 0);
                    int lastDot = prefix.LastIndexOf((byte)'.', prefix.Length - 1, prefix.Length);

                    MetadataNamePart  name  = (lastDot >= 0) ? prefix.GetPart(lastDot + 1) : prefix;
                    NamespaceTreeNode newNs = new NamespaceTreeNode(name);
                    if (ns == null)
                    {
                        newNs.AddType(typeDef);
                    }
                    else
                    {
                        newNs.AddNamespace(ns);
                    }
                    ns = newNs;

                    _names.Add(prefix, ns);

                    prefix = (lastDot >= 0) ? prefix.GetPart(0, lastDot) : MetadataNamePart.Empty;
                }
            }
        }
示例#2
0
        public unsafe void TestPrefixSuffix(string str, char separator, string expectedPrefix, string expectedSuffix)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(str + '\0');
            fixed(byte *fbytes = &bytes[0])
            {
                MetadataName     name = new MetadataName(fbytes, null);
                MetadataNamePart prefix;
                MetadataNamePart suffix;
                MetadataNamePart extent = name.GetExtent();

                int index = extent.IndexOf((byte)separator);

                Assert.That((index < 0), Is.EqualTo((expectedPrefix == null)));

                if (index >= 0)
                {
                    prefix = extent.GetPart(0, index);
                    Assert.That(prefix.ToString(), Is.EqualTo(expectedPrefix));
                    suffix = extent.GetPart(index + 1);
                    Assert.That(suffix.ToString(), Is.EqualTo(expectedSuffix));
                }
            }
        }
示例#3
0
 internal NamespaceTreeNode(MetadataNamePart name)
 {
     Name = name;
 }
示例#4
0
        private List<TypeDef> _typeDefs; // TODO: Use Sequence<TypeDef> (typedefs from the same assembly per chunk/assemblies index)

        #endregion Fields

        #region Constructors

        internal NamespaceTreeNode(MetadataNamePart name)
        {
            _name = name;
        }