A
Ahab Guirguis
hello,
I receive an error with the recursive call......
Can any one see a problem with this approach....
Thanks in advance....
string xml = ToXmlProperties(new TextBox()
FwTextBoxXml.Text = xml;
//--------------------------------------------------------------------------
------
public string ToXmlProperties(Object obj)
{
string xml = String.Empty;
Type t = obj.GetType();
string propertyValue = String.Empty;
xml = "<properties>";
PropertyInfo [] pi = t.GetProperties(BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public);
try
{
foreach (PropertyInfo p in pi)
{
xml += "<property>";
xml += "<name>" + p.Name.ToString() + "</name>";
xml += "<PropertyType>" + p.PropertyType.ToString() + "</PropertyType>";
xml += "<IsClass>" + p.PropertyType.IsClass.ToString() + "</IsClass>";
if ((p.PropertyType.IsClass))
{
object objProperty = p.GetValue(obj, Type.EmptyTypes);
propertyValue = ToXmlProperties(objProperty);
}
else
{
propertyValue = p.GetValue(obj, Type.EmptyTypes).ToString();
}
xml += "<value>" + propertyValue + "</value>";
xml += "</property>";
}
}
catch (System.NullReferenceException ex) {}
xml += "</properties>";
return xml;
}
//--------------------------------------------------------------------------
------
I receive an error with the recursive call......
Can any one see a problem with this approach....
Thanks in advance....
string xml = ToXmlProperties(new TextBox()
FwTextBoxXml.Text = xml;
//--------------------------------------------------------------------------
------
public string ToXmlProperties(Object obj)
{
string xml = String.Empty;
Type t = obj.GetType();
string propertyValue = String.Empty;
xml = "<properties>";
PropertyInfo [] pi = t.GetProperties(BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public);
try
{
foreach (PropertyInfo p in pi)
{
xml += "<property>";
xml += "<name>" + p.Name.ToString() + "</name>";
xml += "<PropertyType>" + p.PropertyType.ToString() + "</PropertyType>";
xml += "<IsClass>" + p.PropertyType.IsClass.ToString() + "</IsClass>";
if ((p.PropertyType.IsClass))
{
object objProperty = p.GetValue(obj, Type.EmptyTypes);
propertyValue = ToXmlProperties(objProperty);
}
else
{
propertyValue = p.GetValue(obj, Type.EmptyTypes).ToString();
}
xml += "<value>" + propertyValue + "</value>";
xml += "</property>";
}
}
catch (System.NullReferenceException ex) {}
xml += "</properties>";
return xml;
}
//--------------------------------------------------------------------------
------