A
Ahab Guirguis
hello,
I receive an error on the recursive call...... The text colored blue is my center of the problem....
The funuction defined below works fine with the exception of sub classes. when the function reaches a sub-class like fonts property or text the function fails with the error
Parameter count mismatch.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Reflection.TargetParameterCountException: Parameter count mismatch.
Can any one see a problem with this code
Thanks in advance....
string xml = ToXmlProperties(new TextBox()
txtXml.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); /* this fails on the sub objects - example fonts... */
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 on the recursive call...... The text colored blue is my center of the problem....
The funuction defined below works fine with the exception of sub classes. when the function reaches a sub-class like fonts property or text the function fails with the error
Parameter count mismatch.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Reflection.TargetParameterCountException: Parameter count mismatch.
Can any one see a problem with this code
Thanks in advance....
string xml = ToXmlProperties(new TextBox()
txtXml.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); /* this fails on the sub objects - example fonts... */
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;
}
//--------------------------------------------------------------------