asp.net代码隐藏查找webmethods
在每个页面的代码隐藏中,如何使用反射来获取我在该页面上定义的所有webmethods 目前,我有以下内容,并在页面_Load()中调用它,但它没有找到我的1静态函数,我有一个webmethod属性asp.net代码隐藏查找webmethods,asp.net,Asp.net,在每个页面的代码隐藏中,如何使用反射来获取我在该页面上定义的所有webmethods 目前,我有以下内容,并在页面_Load()中调用它,但它没有找到我的1静态函数,我有一个webmethod属性 MethodInfo[] methods = this.GetType().GetMethods(); foreach (MethodInfo method in methods) { foreach (Attribute attribute in method.GetCustomAttrib
MethodInfo[] methods = this.GetType().GetMethods();
foreach (MethodInfo method in methods)
{
foreach (Attribute attribute in method.GetCustomAttributes(true))
{
if (attribute is WebMethodAttribute)
{
}
}
}
对于公共静态,请尝试以下操作:
public partial class Default : System.Web.UI.Page
{
public Default()
{
}
protected void Page_Load(object sender, EventArgs e)
{
MethodInfo[] methodInfos = typeof(Default).GetMethods(BindingFlags.Public |
BindingFlags.Static);
foreach (MethodInfo method in methodInfos)
{
foreach (Attribute attribute in method.GetCustomAttributes(true))
{
if (attribute is WebMethodAttribute)
{
}
}
}
}
[WebMethod]
public static void A()
{
}
}
对我来说很好但却一无所获。我肯定这和我看到的物体有关。看起来静态方法并不是真正的部分代码隐藏类或其他东西的一部分。似乎typeof(默认)是缺少的链接。我以为“这个”指的是那个,但我想不是。非常感谢。