Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1279


Ignore:
Timestamp:
03/06/09 17:19:08 (15 years ago)
Author:
epitzer
Message:

Better recursive AutoFormat.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/Util.cs

    r1274 r1279  
    1010    }
    1111    public static string AutoFormat(object o, bool recursive) {
     12      Dictionary<object, int> visitedObjects = new Dictionary<object,int>();
     13      return AutoFormat(o, recursive, visitedObjects);
     14    }
     15    private static string AutoFormat(object o, bool recursive, Dictionary<object, int> visitedObjects) {
    1216      string s = o as string;
    1317      if (s != null)
     
    1519      if (o == null) {
    1620        return "<null>";
     21      }
     22      if (visitedObjects.ContainsKey(o)) {
     23        return o.ToString();
     24      } else {
     25        visitedObjects.Add(o, 0);
     26      }     
     27      if (o.ToString() != o.GetType().ToString()) {
     28        return o.ToString();
    1729      }
    1830      StringBuilder sb = new StringBuilder();
     
    2436        BindingFlags.Instance)) {
    2537        if (mInfo.MemberType == MemberTypes.Field) {
     38          FieldInfo fInfo = (FieldInfo)mInfo;         
    2639          sb.Append(mInfo.Name);
    27           sb.Append("=");
     40          sb.Append("=");         
    2841          if (recursive) {
    29             sb.Append(AutoFormat(((FieldInfo)mInfo).GetValue(o)));
     42            sb.Append(AutoFormat(((FieldInfo)mInfo).GetValue(o), true, visitedObjects));
    3043          } else {
    3144            sb.Append(((FieldInfo)mInfo).GetValue(o));
Note: See TracChangeset for help on using the changeset viewer.