0
喜有可能在私有财产来获取自定义属性反思:私有财产如何提取自定义属性
public class TestAttr
{
[SaveInState]
protected string testPrivate { get { return "test private"; } }
[SaveInState]
public string testPublic { get{ return "test public"; }}
public IDictionary<string, object> dumpVars()
{
IDictionary<string, object> dict = new Dictionary<string, object>();
Type ownerClassType = this.GetType();
foreach (var mi in ownerClassType.GetProperties(BindingFlags.NonPublic))
{
var varAttrib = Attribute.GetCustomAttribute(mi, typeof(SaveInStateAttribute));
if (varAttrib != null)
{
dict.Add(mi.Name, mi.GetValue(this, null));
}
}
return dict;
}
}
感谢
太棒了!谢谢它的作品...,是的,你是对的,但内部课堂是不需要反思,但只是一个例子谢谢 – LXG 2011-03-27 18:11:45