我的类namespace AutoCode.Core.UserControl
{
public class TemplateParamAttribute : Attribute
{ } public class Header : TemplateBase
{
[TemplateParam]
public string Title { get; set; } public Header()
{
this.TemplatePath = HttpContext.Current.Server.MapPath("~/Template/UserControl/");
} public override string ToString()
{
string tp = System.IO.File.ReadAllText(TemplatePath + "Header.ust");
StringTemplate st = new StringTemplate(tp);
st.SetAttribute("Title", Title);
return st.ToString();
}
}
}然后我用Assembly asb = System.Reflection.Assembly.LoadFrom(HttpContext.Current.Server.MapPath("/bin/AutoCode.dll"));
System.Type[] types = asb.GetTypes();
System.Type type = asb.GetType("AutoCode.Core.UserControl." + key);
object o = Activator.CreateInstance(type);
System.Reflection.PropertyInfo[] pi = type.GetProperties(BindingFlags.Public);//这条取不到我的属性
System.Reflection.PropertyInfo[] pi = type.GetProperties();//这条可以取到我的Title属性
//为是为什么呢BindingFlags.Public不是指定说取Public的类型吗
谢谢
{
public class TemplateParamAttribute : Attribute
{ } public class Header : TemplateBase
{
[TemplateParam]
public string Title { get; set; } public Header()
{
this.TemplatePath = HttpContext.Current.Server.MapPath("~/Template/UserControl/");
} public override string ToString()
{
string tp = System.IO.File.ReadAllText(TemplatePath + "Header.ust");
StringTemplate st = new StringTemplate(tp);
st.SetAttribute("Title", Title);
return st.ToString();
}
}
}然后我用Assembly asb = System.Reflection.Assembly.LoadFrom(HttpContext.Current.Server.MapPath("/bin/AutoCode.dll"));
System.Type[] types = asb.GetTypes();
System.Type type = asb.GetType("AutoCode.Core.UserControl." + key);
object o = Activator.CreateInstance(type);
System.Reflection.PropertyInfo[] pi = type.GetProperties(BindingFlags.Public);//这条取不到我的属性
System.Reflection.PropertyInfo[] pi = type.GetProperties();//这条可以取到我的Title属性
//为是为什么呢BindingFlags.Public不是指定说取Public的类型吗
谢谢
你确定取不取?
应该能取到public的成员
返回当前 Type 的所有公共属性 (Property)。
GetProperties(BindingFlags)
当在派生类中重写时,使用指定绑定约束,搜索当前 Type 的.如果属性 (Property) 至少有一个为公共的访问器,则该属性 (Property) 被视为对于反射是公共的。
//获取类型的字段信息
fieldinfo[] myfields=type.GetFiedls()
System.Reflection.PropertyInfo[] pi = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
Try
System.Type type = typeof(AutoCode.Core.UserControl.Header)