我的问题是否有任何方法来检索参数列表及其值使用反射?使用反射获取参数的参数
我想使用反射从PropertyInfo中获取参数列表。
Author author = (Author)attribute;
string name = author.name;
是不行的。因为会有很多属性,这不是typeof Author。
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = true)]
public class Author : Attribute
{
public Author(string name, int v)
{
this.name = name;
version = v;
}
public double version;
public string name;
}
public class TestClass
{
[Author("Bill Gates", 2)]
public TextBox TestPropertyTextBox { get; set; }
}
谢谢。我的情况是,不要使用静态类。所以使用Author author =(Author)属性;不好。我想使用反射从PropertyInfo获取参数列表。 – seasong 2010-09-28 03:16:12
你可以定义参数列表吗? – PostMan 2010-09-28 03:18:41
参数列表是我可以获得(“比尔盖茨”,2)动态使用反射与必须使用“作者”投射属性。因为会有很多这样的Attribute,有些可能不是Author的属性。 – seasong 2010-09-28 03:25:37