private static void SetPublicProperties(Type type, object obj, Dictionary<Type, object> createdObjectReferences)
{
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
ObjectGenerator objectGenerator = new ObjectGenerator();
foreach (PropertyInfo property in properties)
{
if (property.CanWrite)
{
//object propertyValue = objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences);
//property.SetValue(obj, propertyValue, null);
if (property.PropertyType == typeof(String))
{
try
{
XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
object propertyValue = documentation["example"].InnerText.Trim();
property.SetValue(obj, propertyValue, null);
}
catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
}
else if (property.PropertyType == typeof(int))
{
try
{
XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
object propertyValue = int.Parse(documentation["example"].InnerText.Trim());
property.SetValue(obj, propertyValue, null);
}
catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
}
else if (property.PropertyType == typeof(long))
{
try
{
XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
object propertyValue = long.Parse(documentation["example"].InnerText.Trim());
property.SetValue(obj, propertyValue, null);
}
catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
}
else if (property.PropertyType == typeof(DateTime))
{
try
{
XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
object propertyValue = DateTime.Parse(documentation["example"].InnerText.Trim());
property.SetValue(obj, propertyValue, null);
}
catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
}
else
{
object propertyValue = objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences);
property.SetValue(obj, propertyValue, null);
}
}
}
}