完成按键输入按键显示
This commit is contained in:
@@ -54,7 +54,8 @@ namespace NBF
|
||||
}
|
||||
|
||||
// 获取所有方法,包括公共、非公共、实例和静态方法
|
||||
MethodInfo[] allMethods = classType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic);
|
||||
MethodInfo[] allMethods =
|
||||
classType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
foreach (MethodInfo method in allMethods)
|
||||
{
|
||||
@@ -66,5 +67,35 @@ namespace NBF
|
||||
|
||||
return methodsWithAttribute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有标记指定特性的方法
|
||||
/// </summary>
|
||||
/// <param name="classType">查找类</param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<MethodInfo, T> GetMethodsAttribute<T>(Type classType) where T : Attribute
|
||||
{
|
||||
Dictionary<MethodInfo, T> methodsWithAttribute = new Dictionary<MethodInfo, T>();
|
||||
|
||||
if (classType == null)
|
||||
{
|
||||
return methodsWithAttribute;
|
||||
}
|
||||
|
||||
// 获取所有方法,包括公共、非公共、实例和静态方法
|
||||
MethodInfo[] allMethods =
|
||||
classType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
foreach (MethodInfo method in allMethods)
|
||||
{
|
||||
var attribute = method.GetCustomAttribute<T>();
|
||||
if (attribute != null)
|
||||
{
|
||||
methodsWithAttribute[method] = attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return methodsWithAttribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user