Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override string ToString()
- {
- Type thisType = this.GetType();
- // You must specify the Instance and Public flags to get the public
- //instance properties.
- //See:
- //Note: if take the static IPhone4S you get stackoverflow exception!!!
- PropertyInfo[] properties =
- thisType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
- //This code is in separate private method "AppendPropertiesNamesAndValues(properties)"
- //-------------------------------------------------------------------------
- StringBuilder phoneInfo = new StringBuilder();
- phoneInfo.AppendLine("/-----Phone Info-----/\n");
- foreach (var property in properties)
- {
- var propertyValue = property.GetValue(this) ?? "null";
- phoneInfo.AppendLine(property.Name + ": " + propertyValue);
- }
- phoneInfo.AppendLine("/-------------------/");
- //-------------------------------------------------------------------------
- return phoneInfo.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement