//----< write details of element with enumerable Data to string >------ public static string showElement <Key, Data, T>(this DBElement <Key, Data> elem) where Data : IEnumerable <T> // constraint clause { StringBuilder accum = new StringBuilder(); accum.Append(elem.showMetaData()); if (elem.payload != null) { IEnumerable <object> d = elem.payload as IEnumerable <object>; if (d == null) { accum.Append(String.Format("\n payload: {0}", elem.payload.ToString())); } else { bool first = true; accum.Append(String.Format("\n payload:\n ")); foreach (var item in elem.payload) // won't compile without constraint clause { if (first) { accum.Append(String.Format(" {0}", item)); first = false; } else { accum.Append(String.Format(", {0}", item)); } } } } return(accum.ToString()); }
//----< write details of element with simple Data to string >---------- public static string showElement <Key, Data>(this DBElement <Key, Data> elem) { StringBuilder accum = new StringBuilder(); accum.Append(elem.showMetaData()); if (elem.payload != null) { accum.Append(String.Format("\n payload: {0}", elem.payload.ToString())); } return(accum.ToString()); }