本文整理汇总了C#中HashSet.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.ToLookup方法的具体用法?C# HashSet.ToLookup怎么用?C# HashSet.ToLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.ToLookup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var links = new HashSet<Link>((IList<Link>)value, new LinkEqualityComparer());
writer.WriteStartObject();
var lookup = links.ToLookup(l => l.Rel);
foreach (var rel in lookup)
{
writer.WritePropertyName(rel.Key);
if (rel.Count() > 1)
writer.WriteStartArray();
foreach (var link in rel)
{
writer.WriteStartObject();
writer.WritePropertyName("href");
writer.WriteValue(ResolveUri(link.Href));
if (link.IsTemplated)
{
writer.WritePropertyName("templated");
writer.WriteValue(true);
}
writer.WriteEndObject();
}
if (rel.Count() > 1)
writer.WriteEndArray();
}
writer.WriteEndObject();
}
示例2: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var links = new HashSet<Link>((IList<Link>)value, Link.EqualityComparer);
var lookup = links.ToLookup(l => l.Rel);
if (lookup.Count == 0)
return;
writer.WriteStartObject();
foreach (var rel in lookup)
{
var count = rel.Count();
writer.WritePropertyName(rel.Key);
if ((count > 1) || (rel.Key == Link.RelForCuries))
writer.WriteStartArray();
foreach (var link in rel)
WriteLink(writer, link);
if ((count > 1) || (rel.Key == Link.RelForCuries))
writer.WriteEndArray();
}
writer.WriteEndObject();
}
示例3: Initialize
private void Initialize()
{
if (null == _consumingMethod)
throw new InvalidOperationException("Consuming method has not been defined");
if (!_assemblies.Any())
throw new InvalidOperationException("There are no assemblies to scan");
var types = _assemblies
.SelectMany(a => {
try
{
return a.GetExportedTypes();
} catch{}
return new Type[0];
}).Where(x=>x!=null)
.ToList();
var messageTypes = types.Where(x => !x.IsInterface && typeof(IMessage).IsAssignableFrom(x)).ToArray();
var consumerTypes = types.Where(x => typeof(IConsume).IsAssignableFrom(x)).ToArray();
var consumingDirectly = consumerTypes
.SelectMany(consumerType =>
GetConsumedMessages(consumerType)
.Select(messageType => new MessageMapping(consumerType, messageType, true)))
.ToArray();
var result = new HashSet<MessageMapping>();
foreach (var m in consumingDirectly)
{
result.Add(m);
}
var allMessages = result.Select(m => m.Message).ToList();
foreach (var messageType in messageTypes)
{
if (!allMessages.Contains(messageType))
{
allMessages.Add(messageType);
result.Add(new MessageMapping(typeof(MessageMapping.BusNull), messageType, true));
}
}
_consumerInfos = result
.GroupBy(x => x.Consumer)
.Select(x =>
{
var directs = x
.Where(m => m.Direct)
.Select(m => m.Message)
.Distinct();
var assignables = x
.Select(m => m.Message)
.Where(t => directs.Any(d => d.IsAssignableFrom(t)))
.Distinct();
return new ConsumerInfo(x.Key, assignables.ToArray());
}).ToList();
_messageInfos = result
.ToLookup(x => x.Message)
.Select(x =>
{
var domainConsumers = x
.Where(t => t.Consumer != typeof(MessageMapping.BusNull))
.ToArray();
return new MessageInfo
{
MessageType = x.Key,
AllConsumers = domainConsumers.Select(m => m.Consumer).Distinct().ToArray(),
DerivedConsumers = domainConsumers.Where(m => !m.Direct).Select(m => m.Consumer).Distinct().ToArray(),
DirectConsumers = domainConsumers.Where(m => m.Direct).Select(m => m.Consumer).Distinct().ToArray(),
};
}).ToList();
var includedTypes = _messageInfos
.Select(m => m.MessageType).ToList();
// message directory should still include all messages for the serializers
var orphanedMessages = result
.Where(m => !includedTypes.Contains(m.Message))
.Select(m => new MessageInfo
{
MessageType = m.Message,
AllConsumers = Type.EmptyTypes,
DerivedConsumers = Type.EmptyTypes,
DirectConsumers = Type.EmptyTypes
});
_messageInfos.AddRange(orphanedMessages);
}
示例4: Remove
public void Remove(bool prompt)
{
var selectedViewNames = new HashSet<ViewName>(chooseViewsControl1.SelectedViews);
if (selectedViewNames.Count == 0)
{
return;
}
string message;
if (selectedViewNames.Count == 1)
{
message = string.Format(Resources.ManageViewsForm_BtnRemoveOnClick_Are_you_sure_you_want_to_delete_the_view___0___, selectedViewNames.First().Name);
}
else
{
message = string.Format(Resources.ManageViewsForm_BtnRemoveOnClick_Are_you_sure_you_want_to_delete_these__0__views_, selectedViewNames.Count);
}
if (prompt && ViewContext.ShowMessageBox(this, message, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
var namesByGroup = selectedViewNames.ToLookup(name => name.GroupId, name => name.Name);
foreach (var grouping in namesByGroup)
{
ViewContext.DeleteViews(grouping.Key, grouping);
}
}
示例5: NamespaceCasingConsistent
public void NamespaceCasingConsistent()
{
var nameSpaces = new HashSet<string>();
foreach (var type in Types)
{
nameSpaces.Add(type.Namespace);
for (int i = 0; i < type.Namespace.Length; i++)
{
if (type.Namespace[i] == '.')
{
nameSpaces.Add(type.Namespace.Substring(0, i));
}
}
foreach (var g in nameSpaces.ToLookup(s => s.ToUpperInvariant()))
{
if (g.Count() > 1)
{
throw new Exception(string.Format("Found many casings {0}: {1}", g.Key, string.Join(",", g)));
}
}
}
}