private static PropertyInfo[] GetProperties(object obj)
{
return obj.GetType().GetProperties();
}
private static FieldInfo[] GetFields(object obj)
{
return obj.GetType().GetFields();
}
private void AddDataItem(ListView listView, List<String> data)
{
if (data.Count > 0)
{
ListViewItem temp = new ListViewItem(data[0]);
for (int i = 1; i < data.Count; i++)
{
temp.SubItems.Add(data[i]);
}
listView.Items.Add(temp);
}
}
private void TV_Main_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode selected = TV_Main.SelectedNode;
if (selected != null)
{
LV_MainProperties.Items.Clear();
if (selected.Tag != null)
{
Object obj = selected.Tag;
var properties = GetProperties(obj);
foreach (var p in properties)
{
try
{
if (p.PropertyType == typeof(Hashtable))
{
object propVal = p.GetValue(p, null);
Hashtable h = (Hashtable)propVal;
foreach (DictionaryEntry entry in h)
{
AddDataItem(LV_MainProperties, new List<String> { entry.Key.ToString(), entry.Value.ToString() });
}
}
else
{
string name = p.Name;
var value = p.GetValue(obj, null);
AddDataItem(LV_MainProperties, new List<String> { name, value.ToString() });
}
}
catch
{
}
}
var fields = GetFields(obj);
foreach (var f in fields)
{
try
{
if (f.FieldType == typeof(Hashtable))
{
object propVal = f.GetValue(f);
Hashtable h = (Hashtable)propVal;
foreach (DictionaryEntry entry in h)
{
AddDataItem(LV_MainProperties, new List<String> { entry.Key.ToString(), entry.Value.ToString() });
}
}
else
{
string name = f.Name;
var value = f.GetValue(obj);
AddDataItem(LV_MainProperties, new List<String> { name, value.ToString() });
}
}
catch
{
}
}
}
}
}
if (p.ReflectedType == typeof(Hashtable))
{
Hashtable ht = (Hashtable)p;
//do whatever you need with this hashtable...
public class RunnerDetail
{
...
Hashtable _winTable = new Hashtable();
...
public Hashtable winTable
{
get { return _winTable; }
set { _winTable = value; }
}
...
PropertyInfo[] props = obj.GetType().GetProperties();
foreach (var p in props)
{
try
{
if (p.PropertyType == typeof(Hashtable))
{
String message = "bob";
}
else if (p.ReflectedType == typeof(Hashtable))
{
Hashtable ht = (Hashtable)p.GetValue(obj);
foreach (DictionaryEntry entry in ht)
{
AddDataItem(LV_MainProperties, new List<String> { entry.Key.ToString(), entry.Value.ToString() });
}
}
else
{
string name = p.Name;
var value = p.GetValue(obj);
AddDataItem(LV_MainProperties, new List<String> { name, value.ToString() });
}
}
catch (Exception ex)
{
String message = ex.Message;
}
}
Hashtable ht = (Hashtable)p.GetValue(obj);
PropertyInfo[] props =[b] obj.[/b]GetType().GetProperties();
TreeNode selected = TV_Main.SelectedNode;
if (selected != null)
{
LV_MainProperties.Items.Clear();
if (selected.Tag != null)
{
Object obj = selected.Tag;
The test p.ReflectedType does return a Hashtable but then the castbut
If I use
Open in new window
Then I do find the Type but propVal is the Hashtable class not the instance.