Exemplo n.º 1
0
        public void CreateInstanceFromTypeNameTest()
        {
            var dllname = "Generated.dll";

            MakeDll(dllname);
            File.Exists(dllname).Should().BeTrue();

            var asmName  = Path.GetFileNameWithoutExtension(dllname);
            var xelement = new XElement("Ftp", new XAttribute("Class", $"X2, {asmName}"));
            var result   = ActivatorUtils.CreateInstanceFromTypeName <I1>(xelement);

            result.Should().NotBeNull();
            (result is I1).Should().BeTrue();

            File.Delete(dllname);
            File.Exists(dllname).Should().BeFalse();
        }
Exemplo n.º 2
0
        public void CreateInstanceFromTypeNameTestOtherDir()
        {
            var otherDirname    = "Other";
            var dllNameOtherDir = Path.Combine(otherDirname, "Generated2.dll");

            MakeDll(dllNameOtherDir);
            var asmName  = Path.GetFileNameWithoutExtension(dllNameOtherDir);
            var xelement = new XElement("Ftp", new XAttribute("Class", $"X2, {asmName}"));
            var result   = ActivatorUtils.CreateInstanceFromTypeName <I1>(xelement);

            result.Should().BeNull();

            var xelementWithExtraPath = new XElement("Ftp", new XAttribute("Class", $"X2, {asmName}"), new XAttribute("ExtraPaths", otherDirname));

            result = ActivatorUtils.CreateInstanceFromTypeName <I1>(xelementWithExtraPath);
            result.Should().NotBeNull();
            (result is I1).Should().BeTrue();
        }