Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Dll中提取其他方法信息_C#_Dll - Fatal编程技术网

C# 从Dll中提取其他方法信息

C# 从Dll中提取其他方法信息,c#,dll,C#,Dll,在我的解决方案中,我有dll,其中包含以下格式的方法 [TestMethod] [TestProperty("Priority", "P0")] [TestProperty("Owner", "vbnmg")] [TestProperty("Title", "Verify the log accessible")] [TestProperty("ID", "1")] public void LogAccesiblityTest() {

在我的解决方案中,我有dll,其中包含以下格式的方法

    [TestMethod]
    [TestProperty("Priority", "P0")]
    [TestProperty("Owner", "vbnmg")]
    [TestProperty("Title", "Verify the log accessible")]
    [TestProperty("ID", "1")]
    public void LogAccesiblityTest()
    {
    //Test Code
    }
某些方法具有不同的优先级、所有者、ID和标题

通过提供dll名称和serach标准(优先级、所有者、ID和标题),我可以获得在给定优先级组或所有者组中的方法名称等

我有代码,通过它我可以获得所使用的方法名和参数的详细信息,但我不知道如何从test属性中获取信息


有人能建议一下怎么做吗。

听起来你只是在找。考虑到您的格式,我可能会这样写:

public static Dictionary<string, string> GetProperties(MethodInfo method)
{
    return method.GetCustomAttributes(typeof(TestPropertyAttribute), false)
                 .Cast<TestProperty>()
                 .ToDictionary(x => x.Key, x => x.Value);
}
publicstaticdictionary GetProperties(MethodInfo方法)
{
return方法.GetCustomAttributes(typeof(TestPropertyAttribute),false)
.Cast()
.ToDictionary(x=>x.Key,x=>x.Value);
}
(当然,这是假设
TestPropertyAttribute
具有
Key
Value
属性。)


若要仅检测属性的存在(您可能希望用于
TestMethodAttribute
),可以使用。

假设您已经拥有
MethodInfo
对象(因为您说您已经拥有获取信息的代码),可以调用以获取这些属性。它还有一个重载,您可以在其中传递要查找的属性的类型。然后,您只需要强制转换结果并检查其属性