本文整理汇总了C#中IEnumerable.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Reverse方法的具体用法?C# IEnumerable.Reverse怎么用?C# IEnumerable.Reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Reverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPolygon
public void AddPolygon(int count, IEnumerable<int> indices, int? tag)
{
PrevalidateGeometry();
//Error out on polygons not matching, for the sake of being consistent with AW and other RWX loaders.
if(indices.Count() != count)
{
throw new InvalidOperationException("Polygon vertex count mismatch.");
}
_currentMeshGeometry.Faces.Add(new Face
{
Indices = indices.ToList(),
MaterialId = _model.AddMaterial(_currentMaterial),
Tag = tag,
Triangles = TessellatePolygon(indices).ToList()
});
if(_currentMaterial.MaterialMode == MaterialMode.Double)
{
_currentMeshGeometry.Faces.Add(new Face
{
Indices = indices.Reverse().ToList(),
MaterialId = _model.AddMaterial(_currentMaterial),
Tag = tag,
Triangles = TessellatePolygon(indices.Reverse()).ToList()
});
}
}
示例2: GatherCurrentJobs
public static List<MinimalJobStats> GatherCurrentJobs(IEnumerable<JobItem> work, string filter)
{
return work
.Reverse()
.Where(x =>
{
if (String.IsNullOrWhiteSpace(filter) || filter == "all")
{
return true;
}
if (filter == "running" && x.Status == JobStatus.Running)
{
return true;
}
if (filter == "failing" && GatherJobHealth(x) == JobHealth.Bad)
{
return true;
}
return false;
})
.Select(x => new MinimalJobStats
{
JobKey = x.JobKey,
Description = x.Description,
CurrentStatus = (InlineScheduler.JobStatus)x.Status,
Health = GatherJobHealth(x),
Report = GatherJobReport(x)
}).ToList();
}
示例3: LoadButtons
private void LoadButtons(IEnumerable<CustomDialogButtonInfo> buttons)
{
const int buttonMargin = 20;
var leftPosition = pnButtons.Width;
var buttonHeight = pnButtons.Height - buttonMargin;
var topPosition = (pnButtons.Height - buttonHeight) / 2;
foreach (var buttonInfo in buttons.Reverse().ToList())
{
var button = new ButtonX();
button.ColorTable = eButtonColor.OrangeWithBackground;
button.Text = buttonInfo.Title;
button.DialogResult = buttonInfo.DialogResult;
button.TextColor = Color.Black;
button.Height = buttonHeight;
button.Width = buttonInfo.Width;
button.Style = eDotNetBarStyle.StyleManagerControlled;
button.Top = topPosition;
button.Anchor = AnchorStyles.Top | AnchorStyles.Right;
leftPosition -= button.Width;
button.Left = leftPosition;
leftPosition -= buttonMargin;
pnButtons.Controls.Add(button);
}
}
示例4: GatherOveralStatistics
public static SchedulerStats GatherOveralStatistics(IEnumerable<WorkItem> _work)
{
var stats = new SchedulerStats();
stats.CurrentJobs = _work
.Reverse()
.Select(x => new SchedulerJobStats
{
WorkKey = x.WorkKey,
Description = x.Description,
CurrentStatus = (SchedulerJobStatus)x.Status,
LastRunStarted = x.LastStart,
LastRunCompleted = x.LastComplete,
PreviousRuns = x.PreviousRuns.Select(xx => new SchedulerJobRunStats
{
Started = xx.Started,
Completed = xx.Completed,
Result = (SchedulerJobRunResult)xx.Result,
ResultMessage = xx.ResultMessage
}).ToList()
}).ToList();
stats.PendingJobs = stats.CurrentJobs.Count(x => x.CurrentStatus == SchedulerJobStatus.Pending);
stats.RunningJobs = stats.CurrentJobs.Count(x => x.CurrentStatus == SchedulerJobStatus.Running);
stats.ScheduledJobs = stats.CurrentJobs.Count(x => x.CurrentStatus == SchedulerJobStatus.Scheduled);
return stats;
}
示例5: VisitNodes
public void VisitNodes( IEnumerable<DependencyObject> nodes )
{
if( nodes == null )
return;
m_collection.AddRange( nodes.Reverse() );
}
示例6: Forecast
public ForecastEntry Forecast(IEnumerable<DataEntry> dataEntries, int period, dynamic strategyParameters)
{
if (period - 1 < 0)
return null;
int numberOfPeriods = strategyParameters.PeriodCount;
if (numberOfPeriods > dataEntries.Count())
throw new ArgumentException("The number of periods can not be greater than the number of entries.");
double value;
if (dataEntries.Count() == 1 || period == 1)
value = dataEntries.ElementAt(0).Value;
else if (period < numberOfPeriods)
value = dataEntries.ElementAt(period - 1).Value;
else if (dataEntries.Count() > 1 && period <= dataEntries.Count() + 1)
value =
dataEntries.Take(period - 1).Reverse().Take(numberOfPeriods).Reverse().Sum(entry => (entry.Value))/
numberOfPeriods;
else
value = dataEntries.Reverse().Take(numberOfPeriods).Reverse().Sum(entry => (entry.Value))/
numberOfPeriods;
return new ForecastEntry
{
Period = period,
DataEntry = period > dataEntries.Count() ? dataEntries.Last() : dataEntries.ElementAt(period - 1),
ForecastValue = value,
ConfidenceIntervalLow = value,
ConfidenceIntervalHigh = value,
IsHoldout = period > dataEntries.Count()*0.7 //holdout data is always 70 percent
};
}
示例7: ArrayOfSingleDigitsToNumber
/// <summary>
/// Convert a list of digits into a number.
/// </summary>
/// <param name="DigitsToConvertToANumber">Digits to convert to a number</param>
/// <returns>The combined number</returns>
private static int ArrayOfSingleDigitsToNumber(IEnumerable<int> DigitsToConvertToANumber)
{
//ie:
//[0] = 3
//[1] = 5
//[2] = 7
// ==> 357
//tally
var RunningTally = 0;
//what we multiple with
var MultiplyValue = 1;
//loop through all of them and multiple everything
foreach (var Digit in DigitsToConvertToANumber.Reverse())
{
//multiply and add it
RunningTally += Digit * MultiplyValue;
//now multiple by 10
MultiplyValue *= 10;
}
//return the result
return RunningTally;
}
示例8: CreatePipeline
/// <summary>
/// Creates an instance of an <see cref="HttpMessageHandler"/> using the <see cref="DelegatingHandler"/> instances
/// provided by <paramref name="handlers"/>. The resulting pipeline can be used to manually create <see cref="HttpClient"/>
/// or <see cref="HttpMessageInvoker"/> instances with customized message handlers.
/// </summary>
/// <param name="innerHandler">The inner handler represents the destination of the HTTP message channel.</param>
/// <param name="handlers">An ordered list of <see cref="DelegatingHandler"/> instances to be invoked as part
/// of sending an <see cref="HttpRequestMessage"/> and receiving an <see cref="HttpResponseMessage"/>.
/// The handlers are invoked in a top-down fashion. That is, the first entry is invoked first for
/// an outbound request message but last for an inbound response message.</param>
/// <returns>The HTTP message channel.</returns>
public static HttpMessageHandler CreatePipeline(HttpMessageHandler innerHandler, IEnumerable<DelegatingHandler> handlers)
{
if (innerHandler == null)
{
throw Error.ArgumentNull("innerHandler");
}
if (handlers == null)
{
return innerHandler;
}
// Wire handlers up in reverse order starting with the inner handler
HttpMessageHandler pipeline = innerHandler;
IEnumerable<DelegatingHandler> reversedHandlers = handlers.Reverse();
foreach (DelegatingHandler handler in reversedHandlers)
{
if (handler == null)
{
throw Error.Argument("handlers", Properties.Resources.DelegatingHandlerArrayContainsNullItem, typeof(DelegatingHandler).Name);
}
if (handler.InnerHandler != null)
{
throw Error.Argument("handlers", Properties.Resources.DelegatingHandlerArrayHasNonNullInnerHandler, typeof(DelegatingHandler).Name, "InnerHandler", handler.GetType().Name);
}
handler.InnerHandler = pipeline;
pipeline = handler;
}
return pipeline;
}
示例9: CreateMultipleFromAudioData
/// <summary>
/// Creates a set of new Sound Resources based on the specified AudioData, saves it and returns references to it.
/// The incoming AudioData is automatically grouped to the least number of Sounds, according to naming and path conventions.
/// </summary>
/// <param name="baseRes"></param>
/// <returns></returns>
public static List<ContentRef<Sound>> CreateMultipleFromAudioData(IEnumerable<ContentRef<AudioData>> baseRes)
{
char[] trimEndChars = new []{'0','1','2','3','4','5','6','7','8','9','_','-','.','#','~'};
List<ContentRef<AudioData>> sourceData = baseRes.Reverse().ToList();
List<ContentRef<Sound>> result = new List<ContentRef<Sound>>();
// Split data into singular data and grouped data
while (sourceData.Count > 0)
{
ContentRef<AudioData> data = sourceData[sourceData.Count - 1];
string mutualName = data.Name.TrimEnd(trimEndChars);
string mutualDir = System.IO.Path.GetDirectoryName(data.Path);
// Group similar AudioData
List<ContentRef<AudioData>> localGroup = new List<ContentRef<AudioData>>();
for (int i = sourceData.Count - 1; i >= 0; i--)
{
if (System.IO.Path.GetDirectoryName(sourceData[i].Path) != mutualDir) continue;
if (!sourceData[i].Name.StartsWith(mutualName)) continue;
localGroup.Add(sourceData[i]);
sourceData.RemoveAt(i);
}
result.Add(Sound.CreateFromAudioData(localGroup, localGroup.Count > 1 ? mutualName : null));
}
return result;
}
示例10: run
static void run(IEnumerable<String> filePaths)
{
var p = new Parser();
var modules = new Dictionary<String, IReadOnlyList<IClassItem>>();
foreach (var path in filePaths.Reverse())
{
Contract.Assume(path != null);
var txt = File.ReadAllText(path);
var items = p.Parse(txt, ValidationList);
modules.Add(Path.GetFileNameWithoutExtension(path), items.Cast<IClassItem>().ToList());
}
var preludeTxt = File.ReadAllText(libPath + "prelude.ef");
var preludeTxtItems = p.Parse(preludeTxt, ValidationList);
var rw = new Rewriter();
var prog = rw.MakeProgram(preludeTxtItems.Cast<Declr>().ToList(), modules);
var n = new Namer();
n.Name(prog, ValidationList);
var ti = new TypeInferer();
ti.VisitDeclr(prog.GlobalModule);
var i = new Interpreter();
var res = i.Run(prog, ValidationList);
Console.Write("Result: ");
Console.WriteLine(res.Accept(DefaultPrinter));
}
示例11: InsertAfter
/// <summary>
/// Inserts a group of instructions after the target instruction
/// </summary>
public static void InsertAfter(this Mono.Cecil.Cil.ILProcessor processor, Instruction target, IEnumerable<Instruction> instructions)
{
foreach (var instruction in instructions.Reverse())
{
processor.InsertAfter(target, instruction);
}
}
示例12: AddRange
public void AddRange(Player player, IEnumerable<Card> cardCollection, DeckPosition deckPosition)
{
switch (deckPosition)
{
case DeckPosition.Top:
_Cards.InsertRange(0, cardCollection.Reverse());
break;
case DeckPosition.Bottom:
_Cards.AddRange(cardCollection);
break;
}
this.Sort();
if (cardCollection.Count() > 0)
{
if (_AsynchronousChanging)
{
if (_AsynchronousPileChangedEventArgs == null)
_AsynchronousPileChangedEventArgs = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
else
_AsynchronousPileChangedEventArgs.AddedCards.AddRange(cardCollection);
}
else if (PileChanged != null)
{
lock (PileChanged)
{
PileChangedEventArgs pcea = new PileChangedEventArgs(player, PileChangedEventArgs.Operation.Added, cardCollection);
PileChanged(this, pcea);
}
}
}
}
示例13: CreatePipeline
/// <summary>Creates a new instance of the <see cref="T:System.Net.Http.HttpClient" /> which should be pipelined.</summary>
/// <returns>A new instance of the <see cref="T:System.Net.Http.HttpClient" /> which should be pipelined.</returns>
/// <param name="innerHandler">The inner handler which is responsible for processing the HTTP response messages.</param>
/// <param name="handlers">The list of HTTP handler that delegates the processing of HTTP response messages to another handler.</param>
public static HttpMessageHandler CreatePipeline(HttpMessageHandler innerHandler, IEnumerable<DelegatingHandler> handlers)
{
if (innerHandler == null)
{
throw Error.ArgumentNull("innerHandler");
}
if (handlers == null)
{
return innerHandler;
}
HttpMessageHandler handler = innerHandler;
foreach (DelegatingHandler handler2 in handlers.Reverse<DelegatingHandler>())
{
if (handler2 == null)
{
// todo: reenable error throw
throw Error.Argument("handlers", FSR.DelegatingHandlerArrayContainsNullItem, new object[] { typeof(DelegatingHandler).Name });
}
if (handler2.InnerHandler != null)
{
// todo: reenable error throw
throw Error.Argument("handlers", FSR.DelegatingHandlerArrayHasNonNullInnerHandler, new object[] { typeof(DelegatingHandler).Name, "InnerHandler", handler2.GetType().Name });
}
handler2.InnerHandler = handler;
handler = handler2;
}
return handler;
}
示例14: ExpandString
internal string ExpandString(IEnumerable<object> expandedValues)
{
expandedValues = expandedValues.Reverse();
var exValEnumerator = expandedValues.GetEnumerator();
var resultStr = new StringBuilder();
string rest = Value;
// we expand this string in reversed order so we don't need to adjust start indexes
foreach (var item in NestedExpressions.Reverse())
{
if (!exValEnumerator.MoveNext())
{
break;
}
// first find the relative position of the expandable part inside our string
string value = LanguagePrimitives.ConvertTo<string>(exValEnumerator.Current);
var relStart = item.Extent.StartOffset - Extent.StartOffset - 1;
var relEnd = item.Extent.EndOffset - Extent.StartOffset - 1;
// the end are constant words between this expression and the last resolved expression
// we need to resolve escape constants before adding it
var resolvedEnd = StringExpressionHelper.ResolveEscapeCharacters(rest.Substring(relEnd), StringConstantType);
// as we do it in reverse order: insert at the beginning, in reverse order
resultStr.Insert(0, resolvedEnd).Insert(0, value);
// finally strip the rest which needs to be expanded
rest = rest.Substring(0, relStart);
}
// now insert the rest at the beginning (other constant string)
resultStr.Insert(0, StringExpressionHelper.ResolveEscapeCharacters(rest, StringConstantType));
return resultStr.ToString();
}
示例15: KillImpl
/// <summary>
/// Implementation using kill
/// </summary>
/// <param name="pids"></param>
internal static void KillImpl (IEnumerable<int> pids)
{
using (Process quit = new Process ()) {
quit.StartInfo.FileName = "kill";
quit.StartInfo.Arguments = "-QUIT ";
foreach (int pid in pids.Reverse()) {
quit.StartInfo.Arguments += pid.ToString () + " ";
}
quit.StartInfo.UseShellExecute = false;
quit.Start ();
if (!quit.WaitForExit (1000 * 15 /* 15 seconds */))
throw new ApplicationException (string.Format ("The 'kill -QUIT' process didn't exit in 15 seconds."));
}
using (Process kill = new Process ()) {
kill.StartInfo.FileName = "kill";
kill.StartInfo.Arguments = "-9 ";
foreach (int pid in pids) {
kill.StartInfo.Arguments += pid.ToString () + " ";
}
kill.StartInfo.UseShellExecute = false;
kill.Start ();
if (!kill.WaitForExit (1000 * 15 /* 15 seconds */))
throw new ApplicationException (string.Format ("The 'kill' process didn't exit in 15 seconds."));
}
}