我的类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的类型吗
谢谢

解决方案 »

  1.   

    using AutoCode.Core.UserControl..=new()..
      

  2.   

    System.Reflection.PropertyInfo[] pi = type.GetProperties(BindingFlags.Public);//这条取不到我的属性
    你确定取不取?
    应该能取到public的成员
      

  3.   

    GetProperties()(
    返回当前 Type 的所有公共属性 (Property)。 
     GetProperties(BindingFlags)  
    当在派生类中重写时,使用指定绑定约束,搜索当前 Type 的.如果属性 (Property) 至少有一个为公共的访问器,则该属性 (Property) 被视为对于反射是公共的。 
    //获取类型的字段信息 
    fieldinfo[] myfields=type.GetFiedls() 
      

  4.   


    System.Reflection.PropertyInfo[] pi = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
      

  5.   

    GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
    Try
      

  6.   

    是不是因为TYPE没有取对的原因呢System.Type type = asb.GetType("AutoCode.Core.UserControl." + key);换成这句,再试试。
    System.Type type = typeof(AutoCode.Core.UserControl.Header)
      

  7.   

    要么不写BindingFlags参数,要么就不能简单地只写那一个。5、6楼的思路都是对的。