本文整理汇总了C#中IEnumerable.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.SelectMany方法的具体用法?C# IEnumerable.SelectMany怎么用?C# IEnumerable.SelectMany使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.SelectMany方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PotentialLocations
public override IEnumerable<string> PotentialLocations(IEnumerable<string> locations, IDictionary<string, object> extra)
{
string languageName;
if (!TryGetString(extra, "language", out languageName))
return locations;
var extension = languageName + ".spark";
var slashPos = languageName.IndexOf('-');
if (slashPos == -1)
{
return locations.SelectMany(
path => new[]
{
Path.ChangeExtension(path, extension),
path
});
}
var shortExtension = languageName.Substring(0, slashPos) + ".spark";
return locations.SelectMany(
path => new[]
{
Path.ChangeExtension(path, extension),
Path.ChangeExtension(path, shortExtension),
path
});
}
示例2: GetReport
public Report GetReport(IEnumerable<Report> reports)
{
Log.InfoFormat("Merging {0} reports", reports.Count());
var files = reports.SelectMany(x => x.Files)
.GroupBy(x => x.Name)
.Select(x => new File()
{
Name = x.Key,
Annotations = x.SelectMany(y => y.Annotations).ToArray(),
})
.ToArray();
var types = reports.SelectMany(x => x.Types).GroupBy(x => x.Name).Select(x => x.First()).OrderBy(x => x.Display).ToArray();
var typeList = new List<TypeDefinition>(types);
var allTypes = files.SelectMany(x => x.Annotations).Select(x => x.Type).Distinct();
foreach (var type in allTypes.Where(x => types.All(y => !y.Name.Equals(x))))
{
typeList.Add(new TypeDefinition()
{
Name = type,
Color = "#ff0000",
Background = "#f7dede",
Display = type,
});
}
var used = new HashSet<string>(reports.SelectMany(x => x.Files).SelectMany(x => x.Annotations).Select(x => x.Type).Distinct());
return new Report()
{
Files = files,
Types = types.Where(x => used.Contains(x.Name)).ToArray(),
};
}
示例3: Create
public IInstance Create(string name, string remarks, PhysicalAddress macAddress, IEnumerable<Command.Response.Device> roster)
{
Instance instance = new Instance(macAddress, name, remarks);
instance.Observables = roster.SelectMany(device => CreateObservable(instance, device));
instance.Actionables = roster.SelectMany(device => CreateActionable(instance, device));
return instance;
}
示例4: DbInterceptionContext
private DbInterceptionContext(IEnumerable<DbInterceptionContext> copyFrom)
{
_dbContexts = copyFrom.SelectMany(c => c.DbContexts)
.Distinct()
.Where(c => !c.InternalContext.IsDisposed).ToList();
_objectContexts = copyFrom.SelectMany(c => c.ObjectContexts)
.Distinct()
.Where(c => !c.IsDisposed).ToList();
}
示例5: DbMetrics
static void DbMetrics(string caption, IEnumerable<Order> orders)
{
int count = orders.Count();
int lines = orders.SelectMany(ord => ord.Lines).Count();
int totalQty = orders.SelectMany(ord => ord.Lines)
.Sum(line => line.Quantity);
decimal totalValue = orders.SelectMany(ord => ord.Lines)
.Sum(line => line.Quantity * line.UnitPrice);
Console.WriteLine("{0}\torders {1}; lines {2}; units {3}; value {4:C}",
caption, count, lines, totalQty, totalValue);
}
示例6: GetHelpsStatistic
public IEnumerable<UserStatistic> GetHelpsStatistic(IEnumerable<GameDb> games)
{
return Enumerable.Concat(
games.SelectMany(x => x.HomeTeam.Members),
games.SelectMany(x => x.GuestTeam.Members))
.GroupBy(x => x.Id)
.Select(x => new UserStatistic
{
Id = x.Key,
Value = x.Sum(y => y.Help)
});
}
示例7: ValidationResult
/// <summary>
/// Initializes a new instance of the <see cref="ValidationResult"/> class.
/// </summary>
/// <param name="elementResults">The element results.</param>
/// <param name="fieldResults">The field results.</param>
/// <param name="childResults">The child results.</param>
public ValidationResult(IEnumerable<ValidationElementResult> elementResults, IEnumerable<IValidationFieldResult> fieldResults, IEnumerable<ValidationResult> childResults)
{
ElementDirectResults = elementResults.ToList();
ElementDirectFailures = elementResults.Where(result => result.Result.CountsAsFailure).ToList();
ElementResults = childResults.SelectMany(res => res.ElementResults).Union(elementResults.ToList()).ToList();
ElementFailures = ElementResults.Where(result => result.Result.CountsAsFailure);
Results = childResults.SelectMany(res => res.Failures).Union(fieldResults.ToList()).ToList();
Failures = Results.Where(result => result.CountsAsFailure);
ElementResultsCount = ElementResults.AsBindable().Count();
ElementFailureCount = ElementFailures.AsBindable().Count();
ResultsCount = Results.AsBindable().Count();
FailureCount = Failures.AsBindable().Count();
IsSuccessful = FailureCount.Project(count => count == 0);
}
示例8: CreateGenerationTransaction
private GenerationTransaction CreateGenerationTransaction(IEnumerable<Transaction> transactions, uint height, ulong nonce)
{
var antshares = Blockchain.Default.GetUnspentAntShares().GroupBy(p => p.ScriptHash, (k, g) => new
{
ScriptHash = k,
Amount = g.Sum(p => p.Value)
}).OrderBy(p => p.Amount).ThenBy(p => p.ScriptHash).ToArray();
Fixed8 amount_in = transactions.SelectMany(p => p.References.Values.Where(o => o.AssetId == Blockchain.AntCoin.Hash)).Sum(p => p.Value);
Fixed8 amount_out = transactions.SelectMany(p => p.Outputs.Where(o => o.AssetId == Blockchain.AntCoin.Hash)).Sum(p => p.Value);
Fixed8 amount_sysfee = transactions.Sum(p => p.SystemFee);
Fixed8 quantity = Blockchain.Default.GetQuantityIssued(Blockchain.AntCoin.Hash);
List<TransactionOutput> outputs = new List<TransactionOutput>
{
new TransactionOutput
{
AssetId = Blockchain.AntCoin.Hash,
Value = amount_in - amount_out - amount_sysfee,
ScriptHash = wallet.GetContracts().First().ScriptHash
}
};
if (height % Blockchain.MintingInterval == 0 && antshares.Length > 0)
{
ulong n = nonce % (ulong)antshares.Sum(p => p.Amount).GetData();
ulong line = 0;
int i = -1;
do
{
line += (ulong)antshares[++i].Amount.GetData();
} while (line <= n);
outputs.Add(new TransactionOutput
{
AssetId = Blockchain.AntCoin.Hash,
Value = Fixed8.FromDecimal((Blockchain.AntCoin.Amount - (quantity - amount_sysfee)).ToDecimal() * Blockchain.GenerationFactor),
ScriptHash = antshares[i].ScriptHash
});
}
return new GenerationTransaction
{
Nonce = (uint)(nonce % (uint.MaxValue + 1ul)),
Attributes = new TransactionAttribute[0],
Inputs = new TransactionInput[0],
Outputs = outputs.GroupBy(p => p.ScriptHash, (k, g) => new TransactionOutput
{
AssetId = Blockchain.AntCoin.Hash,
Value = g.Sum(p => p.Value),
ScriptHash = k
}).Where(p => p.Value != Fixed8.Zero).ToArray(),
Scripts = new Script[0]
};
}
示例9: CompositeEntitySchema
public CompositeEntitySchema(EntitySchema schema, IEnumerable<EntitySchema> ancestorSchemas, bool copyRelationProxiesFromSchema = false)
: base(schema.Alias, schema.Name)
{
//TODO: Need to move this into a mapper, but not currently one available at the right level
Id = schema.Id;
SchemaType = SchemaType;
AttributeGroups.AddRange(schema.AttributeGroups);
AttributeDefinitions.AddRange(schema.AttributeDefinitions);
UtcCreated = schema.UtcCreated;
UtcModified = schema.UtcModified;
UtcStatusChanged = schema.UtcStatusChanged;
var inheritedDefsDict = new Dictionary<string, InheritedAttributeDefinition>();
var inheritedDefs = ancestorSchemas
.SelectMany(entitySchema => entitySchema.AttributeDefinitions.Select(definition => new InheritedAttributeDefinition(definition, entitySchema))).ToArray();
foreach (var def in inheritedDefs)
{
if (!inheritedDefsDict.ContainsKey(def.Alias))
inheritedDefsDict.Add(def.Alias, def);
}
InheritedAttributeDefinitions = new EntityCollection<InheritedAttributeDefinition>(inheritedDefsDict.Values);
// Need to only show the inherited groups that are exposed by the filtered inherited attribute definitions, but also include empty
// groups so that they have a chance to have some definitions added
var allLinkedGroups = ancestorSchemas.SelectMany(x => x.AttributeDefinitions.Select(y => new InheritedAttributeGroup(y.AttributeGroup, x)));
var allKnownGroups = ancestorSchemas.SelectMany(x => x.AttributeGroups.Select(y => new InheritedAttributeGroup(y, x)));
var unlinkedGroups = allKnownGroups.Except(allLinkedGroups);
var inheritedGroups =
InheritedAttributeDefinitions.Select(x => new InheritedAttributeGroup(x.AttributeGroup, x.Schema)).Union
(unlinkedGroups);
InheritedAttributeGroups = new EntityCollection<InheritedAttributeGroup>(inheritedGroups);
RelationProxies.LazyLoadDelegate = schema.RelationProxies.LazyLoadDelegate;
XmlConfiguration = schema.XmlConfiguration;
if (copyRelationProxiesFromSchema)
{
foreach (var proxies in schema.RelationProxies.GetManualParentProxies())
{
RelationProxies.EnlistParent(proxies.Item.Source, proxies.Item.Type, proxies.Item.Ordinal, proxies.Item.MetaData.ToArray());
}
foreach (var proxies in schema.RelationProxies.GetManualChildProxies())
{
RelationProxies.EnlistParent(proxies.Item.Source, proxies.Item.Type, proxies.Item.Ordinal, proxies.Item.MetaData.ToArray());
}
}
}
示例10: Validate
public static IEnumerable<Error> Validate(
this IEnumerable<SpecificationProperty> specProps,
IEnumerable<Func<IEnumerable<SpecificationProperty>,
IEnumerable<Error>>> rules)
{
return rules.SelectMany(rule => rule(specProps));
}
示例11: ChunkRangesBySize
public static IEnumerable<IndexRange> ChunkRangesBySize(IEnumerable<IndexRange> extents, int pageSizeInBytes)
{
var extentRanges = extents.SelectMany(e => e.PartitionBy(pageSizeInBytes));
var extentQueue = new Queue<IndexRange>(extentRanges);
if (extentQueue.Count == 0)
{
yield break;
}
// move to next start position
do
{
var result = extentQueue.Dequeue();
while (result.Length < pageSizeInBytes && extentQueue.Count > 0)
{
var nextRange = extentQueue.Peek();
if (!nextRange.Abuts(result))
{
break;
}
var mergedRange = nextRange.Merge(result);
if (mergedRange.Length <= pageSizeInBytes)
{
result = mergedRange;
extentQueue.Dequeue();
}
else
{
break;
}
}
yield return result;
} while (extentQueue.Count > 0);
}
示例12: VerifySeedAcceptedNodes
private void VerifySeedAcceptedNodes(
IEnumerable<CstNode> seedCsts, ICollection<CstNode> uppermostSeedAcceptedNodes,
LearningExperiment oracle) {
var anotherUppermostSeedAcceptedNodes = seedCsts
.SelectMany(cst => LearningExperimentUtil
.GetUppermostNodesByNames(cst, SelectedNodeNames))
.Where(oracle.ProtectedIsAcceptedUsingOracle)
.ToList();
var b1 = !uppermostSeedAcceptedNodes.All(oracle.IsAcceptedUsingOracle);
var b2 = anotherUppermostSeedAcceptedNodes
.Select(node => node.AncestorWithSingleChild())
.Any(e => !uppermostSeedAcceptedNodes.Contains(e));
var b3 = uppermostSeedAcceptedNodes.Count != anotherUppermostSeedAcceptedNodes.Count;
Console.WriteLine("Initial: " + string.Join(", ", oracle.OracleNames));
Console.WriteLine("Learned: " + string.Join(", ", SelectedNodeNames));
if (b1 || b2 || b3) {
Console.WriteLine("--------------------------------------------------");
foreach (var e in uppermostSeedAcceptedNodes) {
Console.WriteLine(e);
}
Console.WriteLine("--------------------------------------------------");
foreach (var e in anotherUppermostSeedAcceptedNodes) {
Console.WriteLine(e);
}
throw new Exception("Wrong Oracle.");
}
}
示例13: ResidentSecurity
public ResidentSecurity(IEnumerable<IResourceAuthProvider> providers)
{
_providers = providers;
_roleToClaims = new Dictionary<string, IEnumerable<Claim>>();
_systemRoles = new HashSet<Claim>(_providers
.SelectMany(x => x.RoleNames)
.Distinct()
.Select(x => new Claim(SystemRoles.RoleClaimType, x)));
foreach (var roleClaim in Roles)
{
_roleToClaims.Add(roleClaim.Value,
_providers
.SelectMany(x => x.Claims(roleClaim.Value)
.Distinct()));
}
}
示例14: GetSubtypes
public static IEnumerable<Type> GetSubtypes( Type inspectedType, IEnumerable<Assembly> assemblies )
{
var assemblyTypes = assemblies.SelectMany( asm => asm.GetExportedTypes() ).Where( t => t != null && t != inspectedType );
if ( inspectedType.IsInterface )
{
// todo: generic interfaces
var implementers = assemblyTypes.Where( t => inspectedType.IsAssignableFrom( t ) );
foreach ( var implementer in implementers )
{
if ( implementer.BaseType == null )
yield return implementer;
else if ( !implementer.BaseType.IsAssignableFrom( inspectedType ) )
yield return implementer;
// base type implements the interface, so this type is not directly related
}
}
else
{
var subTypes = assemblyTypes.Where( asmType => asmType.BaseType == inspectedType );
foreach ( var type in subTypes )
yield return type;
}
}
示例15: GetChatHoursFromChats
public IEnumerable<ChatHour> GetChatHoursFromChats(IEnumerable<Chat> chats)
{
return chats
.SelectMany(
chat => GetSpanningHours(chat)
.Select(time =>
new
{
Chat = chat,
Time = time
}))
.GroupBy(obj => obj.Time.Hour)
.Select(group => new ChatHour
{
Hour = group.First().Time.Hour,
ChatsByDay = new DayCollection(group.Select(item => item.Chat))
});
/*return chats.GroupBy(chat => chat.ChatDate.Hour)
.Select(group =>
new ChatHour
{
Hour = group.Key,
ChatsByDay = new DayCollection(group)
});*/
}