I have one method for push class property into NameValuCollection
private NameValueCollection ObjectToCollection(object objects)
{
NameValueCollection param
Before adding a empty string, check whether the current property is MetaTags
or not. If so, use this function recursively.
private NameValueCollection ObjectToCollection(object objects)
{
NameValueCollection parameter = new NameValueCollection();
Type type = objects.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance |
BindingFlags.DeclaredOnly |
BindingFlags.Public);
foreach (PropertyInfo property in properties)
{
if (property.PropertyType == typeof(MetaTags))
{
parameter.Add(property.Name.ToString(),ObjectToCollection(property.GetValue(objects, null)))
}
else{
if (property.GetValue(objects, null) == null)
{
parameter.Add(property.Name.ToString(), "");
}
else
{
if (property.GetValue(objects, null).ToString() != "removeProp")
{
parameter.Add(property.Name.ToString(), property.GetValue(objects, null).ToString());
}
}
}
}
return parameter;
}