Beispiel #1
0
        public void ImportNewTypeReference()
        {
            var assembly         = Utilities.CreateTempNetAssembly();
            var tableStream      = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>();
            var importer         = new ReferenceImporter(tableStream);
            var typeRefTable     = tableStream.GetTable <TypeReference>();
            var assemblyRefTable = tableStream.GetTable <AssemblyReference>();

            const string typeNamespace = "System.Windows.Forms";
            const string typeName      = "Form";

            var assemblyDescr = new ReflectionAssemblyNameWrapper(typeof(Form).Assembly.GetName());
            var reference     = new TypeReference(importer.ImportAssembly(assemblyDescr), typeNamespace, typeName);

            var newReference = importer.ImportType(reference);

            Assert.AreNotSame(reference, newReference,
                              "Imported reference is the same object as original.");
            Assert.IsTrue(typeRefTable.Contains(newReference),
                          "Imported reference not added to reference table.");

            Assert.IsTrue(_comparer.MatchTypes(reference, newReference),
                          "Imported reference does not match original.");

            Assert.IsTrue(assemblyRefTable.FirstOrDefault(x => _comparer.MatchAssemblies(x, assemblyDescr)) != null,
                          "Assembly reference not added to reference table.");
        }
        public void ImportReflectionAssembly()
        {
            var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true);
            var image    = assembly.NetDirectory.MetadataHeader.LockMetadata();
            var importer = new ReferenceImporter(image);

            var assemblyName = typeof(Form).Assembly.GetName();

            var wrapper      = new ReflectionAssemblyNameWrapper(assemblyName);
            var newReference = importer.ImportAssembly(assemblyName);

            Assert.Contains(newReference, image.Assembly.AssemblyReferences);
            Assert.True(_comparer.Equals(wrapper, newReference));
        }
Beispiel #3
0
        public void ImportReflectionAssembly()
        {
            var assembly    = Utilities.CreateTempNetAssembly();
            var tableStream = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>();
            var importer    = new ReferenceImporter(tableStream);
            var refTable    = tableStream.GetTable <AssemblyReference>();

            var assemblyName = typeof(Form).Assembly.GetName();

            var wrapper      = new ReflectionAssemblyNameWrapper(assemblyName);
            var newReference = importer.ImportAssembly(assemblyName);

            Assert.IsTrue(refTable.Contains(newReference), "Imported reference not added to reference table.");
            Assert.IsTrue(_comparer.MatchAssemblies(wrapper, newReference), "Imported reference does not match original.");
        }
        public void ImportReflectionType()
        {
            var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true);
            var image    = assembly.NetDirectory.MetadataHeader.LockMetadata();
            var importer = new ReferenceImporter(image);

            var assemblyDescr = new ReflectionAssemblyNameWrapper(typeof(Form).Assembly.GetName());

            var expected     = new TypeReference(new AssemblyReference(assemblyDescr), typeof(Form).Namespace, typeof(Form).Name);
            var newReference = importer.ImportType(typeof(Form));

            Assert.Equal(expected, newReference, _comparer);
            Assert.Equal(image, newReference.Image);
            Assert.Contains(image.Assembly.AssemblyReferences, x => _comparer.Equals(x, assemblyDescr));
        }
Beispiel #5
0
        public void ImportReflectionType()
        {
            var assembly         = Utilities.CreateTempNetAssembly();
            var tableStream      = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>();
            var importer         = new ReferenceImporter(tableStream);
            var typeRefTable     = tableStream.GetTable <TypeReference>();
            var assemblyRefTable = tableStream.GetTable <AssemblyReference>();

            var assemblyDescr = new ReflectionAssemblyNameWrapper(typeof(Form).Assembly.GetName());

            var expected     = new TypeReference(new AssemblyReference(assemblyDescr), typeof(Form).Namespace, typeof(Form).Name);
            var newReference = importer.ImportType(typeof(Form));

            Assert.IsTrue(_comparer.MatchTypes(expected, newReference),
                          "Imported reference does not match original.");

            Assert.IsTrue(assemblyRefTable.FirstOrDefault(x => _comparer.MatchAssemblies(x, assemblyDescr)) != null,
                          "Assembly reference not added to reference table.");
        }
        public void ImportNewTypeReference()
        {
            var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true);
            var image    = assembly.NetDirectory.MetadataHeader.LockMetadata();
            var importer = new ReferenceImporter(image);

            const string typeNamespace = "System.Windows.Forms";
            const string typeName      = "Form";

            var assemblyDescr = new ReflectionAssemblyNameWrapper(typeof(Form).Assembly.GetName());
            var reference     = new TypeReference(importer.ImportAssembly(assemblyDescr), typeNamespace, typeName);

            var newReference = importer.ImportType(reference);

            Assert.NotSame(reference, newReference);
            Assert.Equal(image, newReference.Image);
            Assert.Equal(reference, newReference, _comparer);
            Assert.Contains(image.Assembly.AssemblyReferences, x => _comparer.Equals(x, assemblyDescr));
        }