本文整理汇总了C#中IEnumerable.SkipWhile方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.SkipWhile方法的具体用法?C# IEnumerable.SkipWhile怎么用?C# IEnumerable.SkipWhile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.SkipWhile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyPackagesToRepositories
public static IEnumerable<ICommandOutput> CopyPackagesToRepositories(this IPackageManager manager,
DependencyResolutionResult dependencies,
IEnumerable<IPackageRepository> repositoriesToWriteTo)
{
if (manager == null) throw new ArgumentNullException("manager");
if (dependencies == null) throw new ArgumentNullException("dependencies");
if (repositoriesToWriteTo == null) throw new ArgumentNullException("repositoriesToWriteTo");
if (!dependencies.IsSuccess)
{
yield return DependencyResolutionFailed(dependencies);
yield break;
}
foreach (var dependency in dependencies.Dependencies)
{
// fast forward to the source repository
var repositoriesForDependency = repositoriesToWriteTo
.SkipWhile(x => x != dependency.Package.Source)
.Skip(1)
.ToList();
if (repositoriesForDependency.Count == 0)
repositoriesForDependency = repositoriesToWriteTo.ToList();
foreach (var repository in repositoriesForDependency.Where(x => x != null && x.CanPublish))
{
yield return new Result("Copying '{0}' to '{1}'", dependency.Package.FullName, repository.Name);
manager.UpdateDependency(dependency, repository);
}
}
}
示例2: GetInterval
private static TimeSpan GetInterval(IEnumerable<string> args)
{
return TimeSpan.FromMilliseconds(args
.SkipWhile(a => a != "-interval")
.Skip(1)
.Select(int.Parse)
.DefaultIfEmpty(100)
.First());
}
示例3: GetInterval
private static int GetInterval(IEnumerable<string> args)
{
return args
.SkipWhile(a => a != "-interval")
.Skip(1)
.Select(int.Parse)
.DefaultIfEmpty(100)
.First();
}
示例4: GetConfig
static IEnumerable<string> GetConfig(IEnumerable<string> configLines, string configName)
{
// Read everything from [configName] up to the next [section].
return configLines
.SkipWhile(l => !l.StartsWith(string.Format("[{0}]", configName), StringComparison.OrdinalIgnoreCase))
.Skip(1)
.TakeWhile(l => !l.StartsWith("[", StringComparison.OrdinalIgnoreCase))
.Where(l => l.Contains('='));
}
示例5: 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);
}
示例6: GetNeighbors
private static IEnumerable<Station> GetNeighbors(Station source, IEnumerable<Station> sortedStations, int maxDeltaZ)
{
var maxZ = source.CartesianLocation.Z;
var minZ = maxZ - maxDeltaZ;
var stations = sortedStations.SkipWhile(station => station.CartesianLocation.Z >= maxZ)
.TakeWhile(station => station.CartesianLocation.Z >= minZ).ToList();
return stations;
}
示例7: SequenceTokensToKeyValuePairEnumerable
private static IEnumerable<KeyValuePair<string, IEnumerable<string>>> SequenceTokensToKeyValuePairEnumerable(
IEnumerable<Token> tokens)
{
return from t in tokens.Pairwise(
(f, s) =>
f.IsName()
? CreateValue(f.Text, tokens.SkipWhile(t => t.Equals(f)).TakeWhile(v => v.IsValue()).Select(x => x.Text).ToArray())
: CreateValue(string.Empty))
where t.Key.Length > 0 && t.Value.Any()
select t;
}
示例8: ForSequence
public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> ForSequence(
IEnumerable<Token> tokens)
{
return from t in tokens.Pairwise(
(f, s) =>
f.IsName()
? f.Text.ToKeyValuePair(tokens.SkipWhile(t => !t.Equals(f)).SkipWhile(t => t.Equals(f)).TakeWhile(v => v.IsValue()).Select(x => x.Text).ToArray())
: string.Empty.ToKeyValuePair())
where t.Key.Length > 0 && t.Value.Any()
select t;
}
示例9: TryPatrol
public bool TryPatrol(IEnumerable<CityBlock> blocks)
{
var eligible = blocks.SkipWhile(x => x.IsPatrolled).ToArray();
if (eligible.Count() < DummyRange)
return false;
foreach (var block in eligible.Take(DummyRange))
block.Force = this;
return true;
}
示例10: 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);
}
示例11: HandleLocation
private ParserContext HandleLocation(IEnumerable<string> parts)
{
var locationParts =
parts.SkipWhile(p => !p.StartsWith("@@"))
.Select(s => new String(s.SkipWhile(c => c.Equals('@')).ToArray())) //Take out the leading @@
.ToArray();
if (!locationParts.Any())
return CurrentParserContext;
CurrentParserContext.ContextLocation = String.Join(" ", locationParts);
return CurrentParserContext;
}
示例12: LoadMcp23008Configuration
private static Hd44780Configuration LoadMcp23008Configuration(IEnumerable<string> args)
{
var addressText = args.SkipWhile(s => !String.Equals(s, "mcp23008", StringComparison.InvariantCultureIgnoreCase)).Skip(1).DefaultIfEmpty("0x20").First();
var address = addressText.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)
? Int32.Parse(addressText.Substring(2), NumberStyles.HexNumber)
: Int32.Parse(addressText);
const Mcp23008Pin registerSelectPin = Mcp23008Pin.Pin1;
const Mcp23008Pin clockPin = Mcp23008Pin.Pin2;
const Mcp23008Pin backlightPin = Mcp23008Pin.Pin7;
var dataPins = new[]
{
Mcp23008Pin.Pin3,
Mcp23008Pin.Pin4,
Mcp23008Pin.Pin5,
Mcp23008Pin.Pin6
};
Console.WriteLine();
Console.WriteLine("Using I2C connection over MCP23008 Expander");
Console.WriteLine("\tRegister Select: {0}", registerSelectPin);
Console.WriteLine("\tClock: {0}", clockPin);
Console.WriteLine("\tData 1: {0}", dataPins[0]);
Console.WriteLine("\tData 2: {0}", dataPins[1]);
Console.WriteLine("\tData 3: {0}", dataPins[2]);
Console.WriteLine("\tData 4: {0}", dataPins[3]);
Console.WriteLine("\tBacklight: {0}", backlightPin);
Console.WriteLine("\tRead/write: GND");
Console.WriteLine();
const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
const ConnectorPin sclPin = ConnectorPin.P1Pin05;
var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()) { ClockDivider = 512 };
var connection = new Mcp23008I2cConnection(driver.Connect(address));
var retVal = new Hd44780Configuration(driver)
{
Pins = new Hd44780Pins(
connection.Out(registerSelectPin),
connection.Out(clockPin),
dataPins.Select(pin => (IOutputBinaryPin)connection.Out(pin)))
};
retVal.Pins.Backlight = connection.Out(backlightPin);
return retVal;
}
示例13: LoadPcf8574Configuration
private static Hd44780Configuration LoadPcf8574Configuration(IEnumerable<string> args)
{
var addressText = args.SkipWhile(s => !String.Equals(s, "pcf8574", StringComparison.InvariantCultureIgnoreCase)).Skip(1).DefaultIfEmpty("0x20").First();
var address = addressText.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)
? Int32.Parse(addressText.Substring(2), NumberStyles.HexNumber)
: Int32.Parse(addressText);
const Pcf8574Pin clockPin = Pcf8574Pin.P2;
const Pcf8574Pin readWritePin = Pcf8574Pin.P1;
const Pcf8574Pin registerSelectPin = Pcf8574Pin.P0;
const Pcf8574Pin backlightPin = Pcf8574Pin.P3;
var dataPins = new[]
{
Pcf8574Pin.P4,
Pcf8574Pin.P5,
Pcf8574Pin.P6,
Pcf8574Pin.P7
};
Console.WriteLine();
Console.WriteLine("Using I2C connection over PCF8574 expander");
Console.WriteLine("\tRegister Select: {0}", registerSelectPin);
Console.WriteLine("\tClock: {0}", clockPin);
Console.WriteLine("\tData 1: {0}", dataPins[0]);
Console.WriteLine("\tData 2: {0}", dataPins[1]);
Console.WriteLine("\tData 3: {0}", dataPins[2]);
Console.WriteLine("\tData 4: {0}", dataPins[3]);
Console.WriteLine("\tBacklight: {0}", backlightPin);
Console.WriteLine("\tRead/write: {0}", readWritePin);
Console.WriteLine();
const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
const ConnectorPin sclPin = ConnectorPin.P1Pin05;
var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()) { ClockDivider = 512 };
var connection = new Pcf8574I2cConnection(driver.Connect(address));
return new Hd44780Configuration(driver)
{
Pins = new Hd44780Pins(
connection.Out(registerSelectPin),
connection.Out(clockPin),
dataPins.Select(p => (IOutputBinaryPin)connection.Out(p)))
{
Backlight = connection.Out(backlightPin),
ReadWrite = connection.Out(readWritePin),
}
};
}
示例14: PartitionSequences
private static IEnumerable<Token> PartitionSequences(
IEnumerable<Token> tokens,
Func<string, Maybe<Tuple<DescriptorType, Maybe<int>>>> typeLookup)
{
return from tseq in tokens.Pairwise(
(f, s) =>
f.IsName() && s.IsValue()
? typeLookup(f.Text).Return(info =>
info.Item1 == DescriptorType.Sequence
? new[] { f }.Concat(tokens.SkipWhile(t => t.Equals(f)).TakeWhile(v => v.IsValue()).Take(MaybeExtensions.Return(info.Item2, items => items, 0)))
: new Token[] { } , new Token[] { })
: new Token[] {})
from t in tseq
select t;
}
示例15: CalcRobotRegexForDomain
/// <summary>
/// Parse robots.txt from a specific prettyURL.
/// Assumes robots.txt is properly formatted.
/// </summary>
/// <param name="prettyURL"></param>
/// <param name="robotsContent"></param>
/// <returns>A regex to determine if a prettyURL is disallowed.</returns>
private Regex CalcRobotRegexForDomain(PrettyURL url, IEnumerable<string> robotsContent)
{
if (CachedRegexes.ContainsKey(url.GetDomain) && DateTime.Now - CachedRegexes[url.GetDomain].Item1 < MaxAge)
{
return CachedRegexes[url.GetDomain].Item2;
}
regexCalcWatch.Restart();
// No restrictions
//
if (robotsContent == null || robotsContent.Count() == 0)
{
return new Regex(@"@.");
}
// Find what is disallowed.
var disallow = robotsContent.SkipWhile(s => !Regex.IsMatch(s, @"User-Agent: \*", RegexOptions.IgnoreCase)) // Start from user agent *.
.TakeWhile(s => !string.IsNullOrWhiteSpace(s)) // Read until blank line (where allow/disallow hopefully ends).
.Skip(1) // Skip the user agent string.
.Where(s => s.StartsWith("Disallow")) // We only need disallowed stuff.
.Select(s => s.Split(':').Last().Trim()); // Select the disallowed stuff.
if (disallow.Count() == 0)
{
return new Regex(@"$.");
}
// Build the regex string
StringBuilder regPattern = new StringBuilder(url + "(" + disallow.First());
foreach (var s in disallow.Skip(1))
{
regPattern.Append('|');
//regPattern.Append(prettyURL);
regPattern.Append(s);
}
regPattern.Append(')');
regPattern.Replace("*", ".*").Replace(".", "\\.").Replace("+", "\\+");
CachedRegexes[url.GetDomain] = new Tuple<DateTime, Regex>(DateTime.Now, new Regex(regPattern.ToString()));
regexCalcWatch.Stop();
regexCalcTimes[url.GetDomain] = (int)regexCalcWatch.Elapsed.TotalMilliseconds;
return CachedRegexes[url.GetDomain].Item2;
}