本文整理汇总了C#中BsonElement.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# BsonElement.OrderBy方法的具体用法?C# BsonElement.OrderBy怎么用?C# BsonElement.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonElement
的用法示例。
在下文中一共展示了BsonElement.OrderBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddItems
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;
}
}
}