static public void DepthFirstPropertyDetails(PropertyDetails parent, int currentDepth = 0, int maxDepth = 3) { PropertyInfo[] props = parent.type.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo propertyInfo in props) { if (propertyInfo.PropertyType.IsPrimitive) { continue; } PropertyDetails newDetails = new PropertyDetails(parent.value, propertyInfo, parent.type); if (null != newDetails.value) { // If we have a base type we depth-first add its details to our own if (currentDepth < maxDepth && null != newDetails.type.Name && newDetails.type.Name != "Object" && !newDetails.type.IsGenericType) { DepthFirstPropertyDetails(newDetails, ++currentDepth); } parent.children.Add(newDetails); } } --currentDepth; }
public TypeReflectionInfo(Object obj, Type type) { this.typeName = obj.GetType().ToString(); this.methods = new List <MethodInfo>(); this.properties = new PropertyDetails(); this.properties.children = new List <PropertyDetails>(); this.properties.name = obj.ToString(); this.properties.readOnly = type.IsValueType; this.properties.type = type; this.properties.value = obj; QSUtils.DepthFirstPropertyDetails(this.properties); }
static public List <string> ConvertTypeReflectionInfoToString(PropertyDetails parentDetails, int indentLevel = 0) { List <string> output = new List <string>(); for (int j = 0; j < parentDetails.children.Count; ++j) { PropertyDetails details = parentDetails.children[j]; String item = string.Format("{0} => {1}", details.name, details.value); item = item.PadLeft(indentLevel); output.Add(item); indentLevel += 2; List <string> childOutput = QSUtils.ConvertTypeReflectionInfoToString(details, indentLevel); output.AddRange(childOutput); indentLevel -= 2; } return(output); }