本文整理汇总了C#中IEnumerable.TakeWhile方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.TakeWhile方法的具体用法?C# IEnumerable.TakeWhile怎么用?C# IEnumerable.TakeWhile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.TakeWhile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIncidentsReverse
static List<DataSample> GetIncidentsReverse(IEnumerable<DataSample> samples, int sessionNumber, int maxTotalIncidents)
{
return IncidentsSupport.FindIncidents(
samples.TakeWhile(data => data.Telemetry.SessionNum == sessionNumber && data.Telemetry.RaceLaps > 0),
d => iRacing.Replay.MoveToPrevIncident(),
maxTotalIncidents);
}
示例2: Arguments
public Arguments(IEnumerable<string> args, IEnumerable<Option> options)
{
if (args == null)
throw new ArgumentNullException("args");
Switches = new Dictionary<string, bool?>(StringComparer.CurrentCultureIgnoreCase);
Variables = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
Parameters = args;
Options = options;
foreach (var argument in Parameters.TakeWhile(item => item.StartsWith("-") &&
item.Length > 1)) {
var name = argument.TrimStart('-');
int colon = name.IndexOf(':');
if (colon > 0) {
var value = name.Substring(colon + 1);
name = name.Substring(0, colon - 1);
name = GetOptionName(name);
Variables[name] = value;
} else {
name = GetOptionName(name);
bool? value = null;
if (name.EndsWith("+")) {
name = argument.Substring(0, name.Length - 1);
value = true;
} else if (name.EndsWith("-")) {
name = name.Substring(0, name.Length - 1);
value = false;
}
Switches[name] = value;
}
}
Parameters = Parameters.Skip(Switches.Count + Variables.Count);
}
示例3: GetIncidentsForward
static List<DataSample> GetIncidentsForward(IEnumerable<DataSample> samples, int maxTotalIncidents)
{
return IncidentsSupport.FindIncidents(
samples.TakeWhile(data => data.Telemetry.SessionState != SessionState.CoolDown),
d => iRacing.Replay.MoveToNextIncident(),
maxTotalIncidents);
}
示例4: Parse
public static PageMeta Parse(IEnumerable<string> lines)
{
var meta = new PageMeta();
foreach (var line in lines.TakeWhile(line => line.StartsWith(MD_META_PREFIX)))
{
var metaType = new string(line.Skip(MD_META_PREFIX.Length).TakeWhile(c => c != ' ').ToArray());
var content = new string(line.Skip(metaType.Length + 3).ToArray());
switch (metaType)
{
case "title":
meta.Title = content;
break;
case "date":
DateTimeOffset articleDate;
if (DateTimeOffset.TryParse(content, out articleDate))
{
meta.Date = articleDate;
}
break;
}
}
return meta;
}
示例5: HandleAction
private ParserContext HandleAction(IEnumerable<string> parts)
{
var actionParts = parts.TakeWhile(s => !s.StartsWith("@")).TakeWhile(s => !s.Equals("@@"));
CurrentParserContext.ContextContent = String.Join(" ", actionParts);
return CurrentParserContext;
}
示例6: Preprocess
public Result<IEnumerable<Token>, Error> Preprocess(
IEnumerable<string> arguments,
Func<IEnumerable<string>, Result<IEnumerable<Token>, Error>> tokenizer)
{
if (arguments.Any(arg => arg.EqualsOrdinal("--")))
{
var tokenizerResult = tokenizer(arguments.TakeWhile(arg => !arg.EqualsOrdinal("--")));
var values = arguments.SkipWhile(arg => !arg.EqualsOrdinal("--")).Skip(1).Select(Token.Value);
return tokenizerResult.Map(tokens => tokens.Concat(values));
}
if (arguments.Any(arg => arg.EqualsOrdinal("//")))
{
var tokenizerResult = tokenizer(arguments.TakeWhile(arg => !arg.EqualsOrdinal("--")));
var values = arguments.SkipWhile(arg => !arg.EqualsOrdinal("//")).Skip(1).Select(Token.Value);
return tokenizerResult.Map(tokens => tokens.Concat(values));
}
return tokenizer(arguments);
}
示例7: GetIncidentsForward
static List<DataSample> GetIncidentsForward(IEnumerable<DataSample> samples, int sampleScanSettle, int maxTotalIncidents)
{
TraceDebug.WriteLine("Scanning for incidents forwards from start");
return IncidentsSupport.FindIncidents(
samples.TakeWhile(data => data.Telemetry.SessionState != SessionState.CoolDown),
sampleScanSettle,
maxTotalIncidents);
}
示例8: PreprocessDashDash
public static StatePair<IEnumerable<Token>> PreprocessDashDash(
IEnumerable<string> arguments,
Func<IEnumerable<string>, StatePair<IEnumerable<Token>>> tokenizer)
{
if (arguments.Any(arg => arg.EqualsOrdinal("--")))
{
var tokenizerResult = tokenizer(arguments.TakeWhile(arg => !arg.EqualsOrdinal("--")));
var values = arguments.SkipWhile(arg => !arg.EqualsOrdinal("--")).Skip(1).Select(Token.Value);
return tokenizerResult.MapValue(tokens => tokens.Concat(values));
}
return tokenizer(arguments);
}
示例9: Produce
public static DigitSequence Produce(IEnumerable<Symbol> symbols,
out IEnumerable<Symbol> symbolsToProcess)
{
// digit-sequence = 1*decimal-digit
IEnumerable<Symbol> digits = symbols.TakeWhile(s =>
s is DecimalDigit);
if (digits.Any())
{
symbolsToProcess = symbols.Skip(digits.Count());
return new DigitSequence(digits);
}
symbolsToProcess = null;
return null;
}
示例10: Produce
public static Expression Produce(IEnumerable<Symbol> symbols)
{
// expression = *whitespace nospace-expression *whitespace
int numSpaceBefore = symbols.TakeWhile(s => s is WhiteSpace).Count();
int numSpaceAfter = symbols.Reverse()
.TakeWhile(s => s is WhiteSpace).Count();
IEnumerable<Symbol> noSpaceSymbolList = symbols
.Skip(numSpaceBefore)
.SkipLast(numSpaceAfter)
.ToList();
NoSpaceExpression n = NoSpaceExpression.Produce(noSpaceSymbolList);
if (null == n)
{
return null;
}
return new Expression(WhiteSpace.CreateWhiteSpace(numSpaceBefore),
n, WhiteSpace.CreateWhiteSpace(numSpaceAfter));
}
示例11: ProcessCommits
public static void ProcessCommits(this IBot bot, string repositoryName ,string lastCommit, IEnumerable<dynamic> commits)
{
// find new commits since
var groupedCommits = commits.TakeWhile(c => c.commit.tree.sha != lastCommit).GroupBy(c => c.committer.login);
// create string to send as message
var sb = new StringBuilder();
sb.AppendFormat("github: there are new commits in the {0} repository\r\n", repositoryName);
foreach (var committer in groupedCommits)
{
sb.AppendFormat("{0} had {1} commits\r\n", committer.Key, committer.Count());
}
// split into rows and send to rooms
var rows = sb.ToString().Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var row in rows)
bot.SayToAllRooms(row);
}
示例12: Produce
public static Expression Produce(IEnumerable<Symbol> symbols)
{
// expression = *whitespace nospace-expression *whitespace
var whiteSpaceBefore = symbols.TakeWhile(s => s is WhiteSpace)
.Count();
var whiteSpaceAfter = symbols.Reverse()
.TakeWhile(s => s is WhiteSpace)
.Count();
var noSpaceSymbolList = symbols.Skip(whiteSpaceBefore)
.SkipLast(whiteSpaceAfter)
.ToList(); // ToList is vital here!
var nospaceExpression = NospaceExpression.Produce(noSpaceSymbolList);
return nospaceExpression == null
? null
: new Expression(
Enumerable.Repeat(new WhiteSpace(), whiteSpaceBefore),
nospaceExpression,
Enumerable.Repeat(new WhiteSpace(), whiteSpaceAfter));
}
示例13: MoveFirst
/// <summary>
/// See if we can move the statement to the front of the line.
/// </summary>
/// <param name="statementToMove"></param>
/// <param name="statements"></param>
/// <returns></returns>
private static bool MoveFirst(IStatement statementToMove, IEnumerable<IStatement> statements)
{
// Walk backwards through previous statements
var prevStatements = statements.TakeWhile(s => s != statementToMove).Reverse();
// See if we can move.
foreach (var s in prevStatements)
{
if (!StatementCommutes(s, statementToMove))
{
return false;
}
}
// If we can commute everywhere, then we are done!
return true;
}
示例14: CreateSegment
private static IEnumerable<string> CreateSegment(IEnumerable<string> current, IEnumerable<string> previous)
{
return current.TakeWhile((step, index) => step == previous.ElementAtOrDefault(index)).ToArray();
}
示例15: PopulateWithRatings
public static void PopulateWithRatings(this List<IUser> users, IEnumerable<IRating> ratings, bool combineDuplicateArtists = false)
{
foreach (var rating in ratings.TakeWhile(rating => rating.UserIndex < users.Count))
users[rating.UserIndex].Ratings.Add(rating);
if (combineDuplicateArtists)
users.CombineDuplicateArtists();
}