本文整理汇总了C#中Collection.Last方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.Last方法的具体用法?C# Collection.Last怎么用?C# Collection.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.Last方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLast
static Instruction GetLast(Collection<Instruction> instructions)
{
var tail = instructions.LastOrDefault(x => x.OpCode == OpCodes.Tail);
if (tail != null)
{
return tail;
}
var last = instructions.Last();
if (last.OpCode == OpCodes.Ret)
{
return last;
}
last = Instruction.Create(OpCodes.Ret);
instructions.Add(last);
return last;
}
示例2: AddCatchBlock
private void AddCatchBlock(Instruction tryStartInstr, Instruction tryEndInstr)
{
var methodCode = method.Body.Instructions;
methodCode.Insert (methodCode.LastIndexOf (tryEndInstr), Instruction.Create (OpCodes.Leave, tryEndInstr)); // needed to jump correctly to catch section
// catch (Exception ex)
// {
// methodExecInfo.Exception = ex;
// BaseAspectAttribute.OnException (methodExecInfo);
// throw;
// }
var exceptionVar = new VariableDefinition (method.Module.Import (typeof (Exception)));
method.Body.Variables.Add (exceptionVar);
var catchCode = new Collection<Instruction>();
catchCode.Add (OpCodes.Stloc, exceptionVar);
catchCode.Add (OpCodes.Ldloc, methodExecInfoVar);
catchCode.Add (OpCodes.Ldloc, exceptionVar);
catchCode.Add (OpCodes.Callvirt, method.Module.Import (typeof (MethodExecInfo).GetProperty ("Exception").SetMethod));
catchCode.Add (BuildOnExceptionCall());
var rethrowInstr = Instruction.Create (OpCodes.Rethrow);
catchCode.Add (BuildCheckExecFlow (rethrowInstr));
catchCode.Add (rethrowInstr);
methodCode.Insert (methodCode.LastIndexOf (tryEndInstr), catchCode);
method.Body.ExceptionHandlers.Add (new ExceptionHandler (ExceptionHandlerType.Catch)
{
CatchType = method.Module.Import (typeof (Exception)),
TryStart = tryStartInstr,
TryEnd = catchCode.First(),
HandlerStart = catchCode.First(),
HandlerEnd = catchCode.Last().Next
});
}
示例3: InsertRangeShouldAddExpectedSubsetOfItems
public void InsertRangeShouldAddExpectedSubsetOfItems()
{
// arrange
var item = new object();
var expected = new[] { item, new object(), new object() };
var target = new Collection<object>() { new object(), new object(), new object() };
// act
target.InsertRange( expected, 3, 1 );
// assert
Assert.Equal( 4, target.Count );
Assert.Equal( item, target.Last() );
}
示例4: AddFinallyBlock
private void AddFinallyBlock(Instruction tryStartInstr, Instruction tryEndInstr)
{
var methodCode = method.Body.Instructions;
methodCode.Insert (methodCode.LastIndexOf (tryEndInstr), Instruction.Create (OpCodes.Leave, tryEndInstr)); // needed to jump correctly to finally section
var finallyCode = new Collection<Instruction>();
finallyCode.Add (BuildOnExitCall());
finallyCode.Add (OpCodes.Endfinally);
methodCode.Insert (methodCode.LastIndexOf (tryEndInstr), finallyCode);
method.Body.ExceptionHandlers.Add (new ExceptionHandler (ExceptionHandlerType.Finally)
{
TryStart = tryStartInstr,
TryEnd = finallyCode.First(),
HandlerStart = finallyCode.First(),
HandlerEnd = finallyCode.Last().Next
});
}
示例5: OpenClick
private void OpenClick(object sender, RoutedEventArgs e)
{
if (IsSaved ? true : (MessageBox.Show("Current font is not saved. Continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes))
{
FontOpenWindow fow = new FontOpenWindow();
fow.Owner = this;
if (fow.ShowDialog() == true)
{
if (fow.Type == 0)
{
CreateSymbolTable();
Stream stream = File.Open(fow.Path, FileMode.Open);
BinaryFormatter bformatter = new BinaryFormatter();
Collection<SymbolStorage> tmp = (Collection<SymbolStorage>)bformatter.Deserialize(stream);
stream.Close();
SymbolTable.Children.Clear();
SymbolButtons = new Collection<SymbolTableButton>();
for (int i = 0; i < tmp.Count; ++i)
{
SymbolButtons.Add(new SymbolTableButton(tmp[i]));
SymbolButtons.Last().Click += new RoutedEventHandler(SymbolClicked);
SymbolButtons.Last().Title = "0x" + (i / 16).ToString("X") + (i % 16).ToString("X");
Grid.SetColumn(SymbolButtons.Last(), (i % 16) * 2);
Grid.SetRow(SymbolButtons.Last(), (i / 16) * 2);
SymbolTable.Children.Add(SymbolButtons.Last());
}
}
SaveFile = fow.Path;
IsSaved = true;
}
}
}