コード例 #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.");
        }
コード例 #2
0
        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));
        }
コード例 #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.");
        }
コード例 #4
0
        public void ImportNewAssembly()
        {
            var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true);
            var image    = assembly.NetDirectory.MetadataHeader.LockMetadata();
            var importer = new ReferenceImporter(image);

            const string assemblyName = "some_lib";
            var          version      = new Version(1, 2, 3, 4);

            var reference    = new AssemblyReference(assemblyName, version);
            var newReference = importer.ImportAssembly(new AssemblyReference(assemblyName, version));

            Assert.NotSame(reference, newReference);
            Assert.Contains(newReference, image.Assembly.AssemblyReferences);
            Assert.Equal(reference, newReference, _comparer);
        }
コード例 #5
0
        public void ImportNewAssembly()
        {
            var assembly    = Utilities.CreateTempNetAssembly();
            var tableStream = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>();
            var refTable    = tableStream.GetTable <AssemblyReference>();
            var importer    = new ReferenceImporter(tableStream);

            const string assemblyName = "some_lib";
            var          version      = new Version(1, 2, 3, 4);

            var reference    = new AssemblyReference(assemblyName, version);
            var newReference = importer.ImportAssembly(new AssemblyReference(assemblyName, version));

            Assert.AreNotSame(reference, newReference, "Imported reference is same object as original.");
            Assert.IsTrue(refTable.Contains(newReference), "Imported reference not added to reference table.");
            Assert.IsTrue(_comparer.MatchAssemblies(reference, newReference), "Imported reference does not match original.");
        }
コード例 #6
0
        public void ImportExistingAssembly()
        {
            var assembly    = Utilities.CreateTempNetAssembly();
            var tableStream = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>();
            var importer    = new ReferenceImporter(tableStream);
            var refTable    = tableStream.GetTable <AssemblyReference>();

            const string assemblyName = "some_lib";
            var          version      = new Version(1, 2, 3, 4);

            var reference = new AssemblyReference(assemblyName, version);

            refTable.Add(reference);

            var newReference = importer.ImportAssembly(new AssemblyReference(assemblyName, version));

            Assert.AreSame(reference, newReference,
                           "Importered reference is not the same object as original.");
        }
コード例 #7
0
        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));
        }