public class FieldInfoClass { protected Button btn; public FieldInfoClass() { btn = new Button(); btn.Text = "test button"; btn.ID = "btn1"; } public void Show() { ShowFields(this.GetType()); //Why cannot get the Text&ID from "btn"?? ShowFields(typeof(FieldInfoClass)); //Why cannot get the Text&ID from "btn"?? ShowProperties(btn.GetType()); //It can be. } public void ShowFields(Type thisGetType) { Console.WriteLine("\n\t\t\t ShowFields"); FieldInfo[] fieldinfo = thisGetType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic); foreach (FieldInfo item in fieldinfo) { if (item.FieldType.ToString().Equals("System.Web.UI.WebControls.Button")) { ShowProperties(item.GetType().BaseType); } } } public void ShowProperties(Type itemGetType) { Console.WriteLine("\n\t\t\t ShowProperties"); PropertyInfo[] propertys = itemGetType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic); Console.WriteLine("\n PropertyInfo "); foreach (PropertyInfo property in propertys) { if (property.Name.ToLower() == "text") { Console.WriteLine("\t\t\t\t\tName : {0}", property.Name); Console.WriteLine("\t\t\t\t\ttext : {0}", property.GetValue(btn, null)); } if (property.Name.ToLower() == "id") { Console.WriteLine("\t\t\t\t\tName : {0}", property.Name); Console.WriteLine("\t\t\t\t\t{0} : {1}", property.Name, property.GetValue(btn, null)); } } } }
//ShowProperties(item.GetType().BaseType); ShowProperties(item.FieldType);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)