如何从完整的程序集字符串中获取程序集名称?
How do I get Assembly name from full assembly string?
我有这样的字符串:
"MyProduct.Framework.Business.ShopBusiness"
但是它自己的程序集名称只有:
"MyProduct.Framework.Business"
我需要像这样创建一个字符串:
"MyProduct.Framework.Business.ShopBusiness, MyProduct.Framework.Business"
因为我正在尝试解决这个问题:
基本上我有这个:
Type executingClass = Type.GetType(TestContext.FullyQualifiedTestClassName);
我需要这样的东西:
Type executingClass = Type.GetType(TestContext.FullyQualifiedTestClassName + ", " + Assembly.FromString(TestContext.FullyQualifiedTestClassName));
有没有像我上面"Assembly.FromString()"发明的内置方法?
换句话说:如何从 TestContext 获取正在执行的测试的程序集名称?
找到最后一个“.”的位置和那个位置的子字符串。
var fullTypeName = "MyProduct.Framework.Business.ShopBusiness";
var typeIndex = assemblyTypeName.LastIndexOf(".");
var namespace = assemblyTypeName.Substring(0, assemblyIndex);
然后添加您的命名空间:
var assemblyQualifiedTypeName = fullTypeName + ", " + namespace
class 命名空间和程序集名称之间没有直接的 link。因此,一般来说,仅从 class 名称中获取完全限定名称是不可能的。
我有这样的字符串:
"MyProduct.Framework.Business.ShopBusiness"
但是它自己的程序集名称只有:
"MyProduct.Framework.Business"
我需要像这样创建一个字符串:
"MyProduct.Framework.Business.ShopBusiness, MyProduct.Framework.Business"
因为我正在尝试解决这个问题:
基本上我有这个:
Type executingClass = Type.GetType(TestContext.FullyQualifiedTestClassName);
我需要这样的东西:
Type executingClass = Type.GetType(TestContext.FullyQualifiedTestClassName + ", " + Assembly.FromString(TestContext.FullyQualifiedTestClassName));
有没有像我上面"Assembly.FromString()"发明的内置方法?
换句话说:如何从 TestContext 获取正在执行的测试的程序集名称?
找到最后一个“.”的位置和那个位置的子字符串。
var fullTypeName = "MyProduct.Framework.Business.ShopBusiness";
var typeIndex = assemblyTypeName.LastIndexOf(".");
var namespace = assemblyTypeName.Substring(0, assemblyIndex);
然后添加您的命名空间:
var assemblyQualifiedTypeName = fullTypeName + ", " + namespace
class 命名空间和程序集名称之间没有直接的 link。因此,一般来说,仅从 class 名称中获取完全限定名称是不可能的。