private void AddItems(BsonElement[] elements, int level, bool alt, MongoDocumentProperty parent, BsonValue objectId, int? arrayIndex = null) { var orderedElements = elements.OrderBy(element => element.Name); foreach (var item in orderedElements) { var mdp = new MongoDocumentProperty { AlternateRow = alt, ArrayIndex = arrayIndex, Depth = level * 20, DocumentObjectId = objectId, Expanded = true, ExpanderVisibility = Visibility.Hidden, FullPath = parent == null ? item.Name : string.Format("{0}{1}{2}", parent.FullPath, arrayIndex == null ? "." : "", item.Name), Id = _nextItemId++, Key = item.Name, TextBoxVisibility = Visibility.Visible, Type = item.Value.BsonType, Value = null, Visible = Visibility.Visible }; if (level == 0 && item.Name == "_id") { mdp.ReadOnly = true; } if (parent != null) { parent.AddChild(mdp); } switch (item.Value.BsonType) { case BsonType.Document: mdp.ExpanderVisibility = Visibility.Visible; mdp.TextBoxVisibility = Visibility.Hidden; mdp.ReadOnly = true; _collectionData.Add(mdp); AddItems(item.Value.AsBsonDocument.ToArray(), level + 1, alt, mdp, objectId); break; case BsonType.Array: mdp.ExpanderVisibility = Visibility.Visible; mdp.TextBoxVisibility = Visibility.Hidden; mdp.ReadOnly = true; _collectionData.Add(mdp); var idx = 0; foreach (var arrayItem in item.Value.AsBsonArray) { AddItems(new[] { new BsonElement(string.Format("[{0}]", idx), arrayItem) }, level + 1, alt, mdp, objectId, idx); idx++; } break; case BsonType.Binary: mdp.Value = Convert.ToBase64String((byte[]) item.Value); mdp.PropertyChanged += DocumentPropertyChanged; _collectionData.Add(mdp); break; default: mdp.Value = item.Value.ToString(); mdp.PropertyChanged += DocumentPropertyChanged; _collectionData.Add(mdp); break; } } }