首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求获取特定Attribute的值解决办法

2012-10-16 
求获取特定Attribute的值[WebService(Namespace http://1.2.3/,Name12344)]public class WebServic

求获取特定Attribute的值
[WebService(Namespace = "http://1.2.3/",Name="12344")]
public class WebService1:System.Web.Services.WebService
{
  ...

  private string getName()
  {
  //怎么得到这个类的WebServiceAttribute中的Name值?
  }
}

求高手,
我只知道一个GetCustomAttributes,问题是他返回的是数组
string s = "";
foreach (object attr in this.GetType().GetCustomAttributes(typeof(WebServiceAttribute), true))
{
if (attr is WebServiceAttribute)
{
s += ((WebServiceAttribute)attr).Name + ";";
}
}
return s;
这样会不会出现多个值啊
有没有其他方法啊

[解决办法]
你说的这方面没怎么用过,
GetCustomAttribute(Name) 应该有个这样的方法
或者说你GetCustomAttributes返回的集合提供一个根据名字的索引[name] 来取出你所要的值
可以试试

热点排行