/// <summary> /// Shows the object. /// </summary> /// <param name="contract">The contract.</param> /// <param name="parentNode">The parent node.</param> private static void ShowObject(object contract, TreeNode parentNode) { if (contract == null) { return; } var contractType = contract.GetType(); var properties = contractType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in properties) { var attributes = property.GetCustomAttributes(true); foreach (var attribute in attributes) { if (attribute is System.Runtime.Serialization.DataMemberAttribute) { var propertyValue = property.GetValue(contract, null); var propertyValueArray = propertyValue as byte[]; string displayValue; if (propertyValueArray != null) { displayValue = "[## Binary data ##]"; } else if (propertyValue == null) { displayValue = "** null **"; } else { displayValue = propertyValue.ToString(); } var newNode = parentNode.Nodes.Add(property.Name + ": " + displayValue); var link = new PropertyLink(contract, property); newNode.Tag = link; var list = propertyValue as IEnumerable; if (propertyValueArray == null && !(propertyValue is string) && list != null) { var counter = -1; foreach (var listObject in list) { counter++; var newNode2 = newNode.Nodes.Add("[" + counter.ToString(System.Globalization.CultureInfo.InvariantCulture) + "]"); ShowObject(listObject, newNode2); } } else { if (propertyValueArray == null) { ShowObject(propertyValue, newNode); } } } } } }
/// <summary> /// Shows the object. /// </summary> /// <param name="contract">The contract.</param> /// <param name="parentNode">The parent node.</param> private static void ShowObject(object contract, TreeNode parentNode) { if (contract == null) { return; } var contractType = contract.GetType(); var properties = contractType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in properties) { var attributes = property.GetCustomAttributes(true); foreach (var attribute in attributes) if (attribute is System.Runtime.Serialization.DataMemberAttribute) { var propertyValue = property.GetValue(contract, null); var propertyValueArray = propertyValue as byte[]; string displayValue; if (propertyValueArray != null) displayValue = "[## Binary data ##]"; else if (propertyValue == null) displayValue = "** null **"; else displayValue = propertyValue.ToString(); var newNode = parentNode.Nodes.Add(property.Name + ": " + displayValue); var link = new PropertyLink(contract, property); newNode.Tag = link; var list = propertyValue as IEnumerable; if (propertyValueArray == null && !(propertyValue is string) && list != null) { var counter = -1; foreach (var listObject in list) { counter++; var newNode2 = newNode.Nodes.Add("[" + counter.ToString(System.Globalization.CultureInfo.InvariantCulture) + "]"); ShowObject(listObject, newNode2); } } else { if (propertyValueArray == null) ShowObject(propertyValue, newNode); } } } }