本文整理汇总了C#中List.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# List.OfType方法的具体用法?C# List.OfType怎么用?C# List.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.OfType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
List<Person> SULSdata = new List<Person>()
{
new SeniorTrainer("Spiro", "Spirov", 33),
new JuniorTrainer("Kiro", "Kirov", 22),
new GraduateStudent("Pesho", "Peshov", 77, 000001, 3.33),
new GraduateStudent("Gosho", "Goshev", 77, 000002, 4.23),
new DropoutStudent("Baba", "Yaga", 88, 000003, 6.00, "To fly more."),
new DropoutStudent("Ivan", "Petrov", 18, 000006, 2.00, "No reason."),
new OnsiteStudent("Yan", "Hon", 31, 000013, 3.50, "OOP", 2),
new OnsiteStudent("Tzun", "Gvan", 19, 000019, 4.41, "OOP", 0),
new OnlineStudent("Maria", "Georgieva", 21, 000119, 2.90, "OOP"),
new OnlineStudent("Smilen", "Svilenov", 45, 000231, 3.80, "OOP"),
};
SULSdata.OfType<CurrentStudent>()
.OrderBy(s => s.AverageGrade)
.ToList()
.ForEach(Console.WriteLine);
Console.WriteLine();
SULSdata.OfType<DropoutStudent>()
.ToList()
.ForEach(s => s.ReApply());
}
示例2: ExploreAssembly
public void ExploreAssembly(IProject project, IMetadataAssembly assembly, UnitTestElementConsumer consumer, ManualResetEvent exitEvent)
{
var envoy = ProjectModelElementEnvoy.Create(project);
if (assembly.ReferencedAssembliesNames.Any(n => n.Name == SilverlightMsTestAssemblyName))
{
var allElements = new List<IUnitTestElement>();
var mappedElements = new Dictionary<IUnitTestElement, IUnitTestElement>();
new mstestlegacy::JetBrains.ReSharper.UnitTestProvider.MSTest.MsTestMetadataExplorer(msTestElementFactory, msTestAttributesProvider, project, shellLocks, allElements.Add)
.ExploreAssembly(assembly);
foreach (var classElement in allElements.OfType<mstest10::JetBrains.ReSharper.UnitTestProvider.MSTest10.MsTestTestClassElement>())
mappedElements.Add(classElement, elementFactory.GetOrCreateClassElement(classElement.TypeName, project, envoy));
foreach (var methodElement in allElements.OfType<mstest10::JetBrains.ReSharper.UnitTestProvider.MSTest10.MsTestTestMethodElement>())
mappedElements.Add(methodElement, elementFactory.GetOrCreateMethodElement(methodElement.Id, project, (mstestlegacy::JetBrains.ReSharper.UnitTestProvider.MSTest.MsTestTestClassElementBase)mappedElements[methodElement.Parent], envoy, methodElement.TypeName));
foreach (var rowElement in allElements.OfType<mstest10::JetBrains.ReSharper.UnitTestProvider.MSTest10.MsTestTestRowElement>())
mappedElements.Add(rowElement, elementFactory.GetOrCreateRowElement(rowElement.Id, project, (mstestlegacy::JetBrains.ReSharper.UnitTestProvider.MSTest.MsTestTestMethodElementBase)mappedElements[rowElement.Parent], envoy));
foreach (var element in allElements)
{
IUnitTestElement mappedElement;
if (mappedElements.TryGetValue(element, out mappedElement))
consumer(mappedElements[element]);
else
consumer(element);
}
}
}
示例3: ProcessTodayPayments
private void ProcessTodayPayments()
{
var todayPayments = _paymentSvc.GetTodayPayments(_expenseController.CurrentSessionData).ToList();
var nextPayments = _paymentSvc.GetComingPayments(_expenseController.CurrentSessionData).ToList();
var latePayments = _paymentSvc.GetLatePayments(_expenseController.CurrentSessionData).ToList();
var form = new FormPendingExpensesViewModel(todayPayments, nextPayments, latePayments);
form.ShowDialog();
//when the form is closed, read the modified data and notify the worksheet.
var processedPayments = new List<BaseTransaction>();
processedPayments.AddRange(EditPendingExpenseDto.ToList(form.TodayPayments, w => w.IsOk == true));
processedPayments.AddRange(EditPendingExpenseDto.ToList(form.LatePayments, w => w.IsOk == true));
processedPayments.AddRange(EditPendingExpenseDto.ToList(form.NextPayments, w => w.IsOk == true));
var processedExpenses = processedPayments.OfType<Expense>();
var processedIncomes = processedPayments.OfType<Income>();
_expenseController.AcceptDataCollection(processedExpenses, true);
_incomeController.AcceptDataCollection(processedIncomes, true);
CommandHandler.Run<ConfigureSidePanelCommand>(new SidePanelCommandArgs
{
WpfControl = new MainSidePanel(),
Transactions = CurrentSession.ValidTransactions,
Accounts = CurrentSession.Accounts
});
}
示例4: Task
public static List<Block> Task(List<Block> blocks)
{
var media = blocks.OfType<MediaBlock>().Select(t => t.MediaQuery);
var import = blocks.OfType<Model.Import>().Select(t => t.MediaQuery);
var @using = blocks.OfType<Model.Using>().Select(t => t.MediaQuery);
var toVerify = media.Union(import).Union(@using).ToList();
toVerify.Each(v => VerifyQuery(v));
var allProps =
blocks.OfType<SelectorAndBlock>().SelectMany(s => s.Properties)
.Union(
blocks.OfType<MediaBlock>().Select(m => m.Blocks).OfType<SelectorAndBlock>().SelectMany(s => s.Properties)
);
var values = allProps.OfType<NameValueProperty>().Select(s => s.Value).ToList();
VerifyCycle(values);
VerifySteps(values);
VerifyCubicBezier(values);
VerifyLinearGradient(values);
return blocks;
}
示例5: PerformRollup
//public static List<FileAction> PerformRollup(List<USNChangeRange> range)
//{
// var deletedFiles = range.Where(e=> e.Entry)
//}
public static List<FileAction> PerformRollup(List<FileAction> toReturn)
{
var deletedFiles = toReturn.OfType<DeleteAction>().ToList();
foreach (var deletedFile in deletedFiles)
{
if (toReturn.OfType<UpdateAction>().Select(f => f.RelativePath).Contains(deletedFile.RelativePath))
{
toReturn.Remove(deletedFile);
}
toReturn.RemoveAll(f => f.RelativePath == deletedFile.RelativePath && f.USN < deletedFile.USN);
}
var fileActions = toReturn.Select(e => e.RelativePath).Distinct().Select(f => toReturn.FirstOrDefault(a => a.RelativePath == f)).ToList();
foreach (var source in fileActions.OfType<RenameAction>().ToList())
{
if (fileActions.Any(f => f.RawPath == source.RenameFrom))
{
fileActions.RemoveAll(f => f.RawPath == source.RenameFrom);
fileActions.Remove(source);
fileActions.Add(new RenameAction()
{
RelativePath = source.RelativePath,
RawPath = source.RawPath,
USN = source.USN,
IsDirectory = source.IsDirectory,
Mountpoint = source.Mountpoint
});
}
}
return fileActions;
}
示例6: OpenIdChannel
/// <summary>
/// Initializes a new instance of the <see cref="OpenIdChannel"/> class.
/// </summary>
/// <param name="messageTypeProvider">A class prepared to analyze incoming messages and indicate what concrete
/// message types can deserialize from it.</param>
/// <param name="bindingElements">The binding elements to use in sending and receiving messages.</param>
protected OpenIdChannel(IMessageFactory messageTypeProvider, IChannelBindingElement[] bindingElements)
: base(messageTypeProvider, bindingElements) {
Requires.NotNull(messageTypeProvider, "messageTypeProvider");
// Customize the binding element order, since we play some tricks for higher
// security and backward compatibility with older OpenID versions.
var outgoingBindingElements = new List<IChannelBindingElement>(bindingElements);
var incomingBindingElements = new List<IChannelBindingElement>(bindingElements);
incomingBindingElements.Reverse();
// Customize the order of the incoming elements by moving the return_to elements in front.
var backwardCompatibility = incomingBindingElements.OfType<BackwardCompatibilityBindingElement>().SingleOrDefault();
var returnToSign = incomingBindingElements.OfType<ReturnToSignatureBindingElement>().SingleOrDefault();
if (backwardCompatibility != null) {
incomingBindingElements.MoveTo(0, backwardCompatibility);
}
if (returnToSign != null) {
// Yes, this is intentionally, shifting the backward compatibility
// binding element to second position.
incomingBindingElements.MoveTo(0, returnToSign);
}
this.CustomizeBindingElementOrder(outgoingBindingElements, incomingBindingElements);
// Change out the standard web request handler to reflect the standard
// OpenID pattern that outgoing web requests are to unknown and untrusted
// servers on the Internet.
this.WebRequestHandler = new UntrustedWebRequestHandler();
}
示例7: Map
public SpatialRecord Map(ISOSpatialRow isoSpatialRow, List<WorkingData> meters)
{
var spatialRecord = new SpatialRecord();
foreach (var meter in meters.OfType<NumericWorkingData>())
{
SetNumericMeterValue(isoSpatialRow, meter, spatialRecord);
}
foreach (var meter in meters.OfType<EnumeratedWorkingData>())
{
SetEnumeratedMeterValue(isoSpatialRow, meter, spatialRecord);
}
spatialRecord.Geometry = new ApplicationDataModel.Shapes.Point
{
X = Convert.ToDouble(isoSpatialRow.EastPosition * CoordinateMultiplier),
Y = Convert.ToDouble(isoSpatialRow.NorthPosition * CoordinateMultiplier),
Z = isoSpatialRow.Elevation
};
spatialRecord.Timestamp = isoSpatialRow.TimeStart;
return spatialRecord;
}
示例8: ReadJsonArray
private static dynamic ReadJsonArray(JsonReader reader)
{
List<dynamic> vals = new List<dynamic>();
while (reader.Read())
{
if (reader.TokenType == JsonToken.EndArray)
{
break;
}
else
{
vals.Add(ReadJsonValue(reader, true));
}
}
if (vals.Count != 0 && vals.All(v => v is IDictionary<string, object>))
{
if (vals.OfType<IDictionary<string, object>>().All(v => v.ContainsKey("Key") && v.ContainsKey("Value")))
{
ExpandoObject obj = new ExpandoObject();
foreach (IDictionary<string, object> dict in vals.OfType<IDictionary<string, object>>())
{
((IDictionary<string, object>)obj).Add(dict["Key"].ToString(), dict["Value"]);
}
return obj;
}
}
return vals;
}
示例9: CreateCopyStream
public static GenericStructure CreateCopyStream(List<MapObject> objects)
{
var stream = new GenericStructure("clipboard");
var entitySolids = objects.OfType<Entity>().SelectMany(x => x.Find(y => y is Solid)).ToList();
stream.Children.AddRange(objects.OfType<Solid>().Where(x => !x.IsCodeHidden && !x.IsVisgroupHidden && !entitySolids.Contains(x)).Select(WriteSolid));
stream.Children.AddRange(objects.OfType<Group>().Select(WriteGroup));
stream.Children.AddRange(objects.OfType<Entity>().Select(WriteEntity));
return stream;
}
示例10: Task
public static List<Block> Task(List<Block> blocks)
{
var media = blocks.OfType<MediaBlock>().Select(t => t.MediaQuery);
var import = blocks.OfType<Model.Import>().Select(t => t.MediaQuery);
var @using = blocks.OfType<Model.Using>().Select(t => t.MediaQuery);
var toVerify = media.Union(import).Union(@using).ToList();
toVerify.Each(v => VerifyQuery(v));
return blocks;
}
示例11: Task
public static List<Block> Task(List<Block> blocks)
{
var resets = blocks.OfType<SelectorAndBlock>().Where(w => w.IsReset).ToList();
var ret = new List<Block>();
ret.AddRange(blocks.Where(w => !(w is SelectorAndBlock || w is MediaBlock)));
ret.AddRange(blocks.OfType<SelectorAndBlock>().Where(w => w.IsReset));
var remaining = blocks.Where(w => !ret.Contains(w)).ToList();
foreach (var block in remaining)
{
var selBlock = block as SelectorAndBlock;
if (selBlock != null)
{
var props = new List<Property>();
var resetProps = selBlock.Properties.OfType<ResetProperty>();
var selfResetProps = selBlock.Properties.OfType<ResetSelfProperty>();
props.AddRange(selBlock.Properties.Where(w => !(resetProps.Contains(w) || selfResetProps.Contains(w))));
var copySels = resetProps.Select(x => x.Selector).Union(selfResetProps.Select(x => x.EffectiveSelector)).ToList();
foreach (var sel in copySels)
{
var newProps = FindMatches(sel, resets);
foreach (var p in newProps)
{
// reset properties never override
if (props.Any(a => a is NameValueProperty && ((NameValueProperty)a).Name.Equals(p.Name, StringComparison.InvariantCultureIgnoreCase))) continue;
props.Add(p);
}
}
ret.Add(new SelectorAndBlock(selBlock.Selector, props, null, selBlock.Start, selBlock.Stop, selBlock.FilePath));
}
var media = block as MediaBlock;
if (media != null)
{
var subBlocks = Task(media.Blocks.ToList());
ret.Add(new MediaBlock(media.MediaQuery, subBlocks, media.Start, media.Start, media.FilePath));
}
}
return ret;
}
示例12: GetRequestMetadata
public RequestMetadata GetRequestMetadata(RequestLog source)
{
var entries = new List<object>(source.LogTable.Rows.Count);
foreach (DataRow row in source.LogTable.Rows)
{
try
{
object entry = mEntryFactory.CreateEntry(row);
if (entry != null)
{
entries.Add(entry);
}
}
catch (ArgumentException exception)
{
Trace.TraceWarning(exception.Message);
}
}
var commandEntries = entries.OfType<CommandEntry>();
return new RequestMetadata
{
Entries = entries,
Statistics = new RequestMetadataStatistics
{
TotalCommands = commandEntries.LongCount(),
TotalDuration = commandEntries.Aggregate(TimeSpan.Zero, (value, entry) => value + entry.Duration),
TotalBytesReceived = commandEntries.Sum(x => x.BytesReceived),
TotalBytesSent = commandEntries.Sum(x => x.BytesSent),
TotalDuplicateCommands = commandEntries.LongCount(x => x.IsDuplicate)
}
};
}
示例13: AppConfig
public AppConfig( string configFile ) {
this.saveFile = configFile;
this.configState = ConfigState.Loading;
this.currencies = new List<Currency>(24);
try {
config = Configuration.LoadFromFile(configFile, Encoding.UTF8);
foreach (Section sec in config) {
Currency c = sec.CreateObject<Currency>();
if (sec["Name"].StringValue.Contains("Chaos")) { c.Value = 1; }
this.currencies.Add(c);
}
}
catch (Exception) {
InitializeCurrency();
config = new Configuration();
byte id = 0;
var currencyData = currencies.OfType<Currency>().OrderBy(item => item.Name).GetEnumerator();
while (currencyData.MoveNext()) {
config.Add(Section.FromObject(SECTION_CURRENCY + id, currencyData.Current));
id++;
}
config.SaveToFile(configFile, Encoding.UTF8);
}
configState = ConfigState.Clean;
}
示例14: RegisterHandles
private void RegisterHandles()
{
UIResizeOperationHandleConnector = new UIResizeOperationHandleConnector(CanvasItem, FrameOfReference,
SnappingEngine);
var thumbContainer = (UIElement) FindName("PART_ThumbContainer");
Debug.Assert(thumbContainer != null, "ThumbContainer part not found!");
var visualChildren = new List<DependencyObject>();
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(thumbContainer); i++)
{
visualChildren.Add(VisualTreeHelper.GetChild(thumbContainer, i));
}
var logicalChildren = visualChildren.OfType<FrameworkElement>();
foreach (var logicalChild in logicalChildren)
{
var childRect = this.GetRectRelativeToParent(logicalChild);
var parentRect = CanvasItem.Rect();
var handlePoint = childRect.GetHandlePoint(parentRect.Size);
UIResizeOperationHandleConnector.RegisterHandle(new UIElementAdapter(logicalChild), handlePoint);
}
}
示例15: Machine
public Machine(byte[] appleIIe, byte[] diskIIRom)
{
Events = new MachineEvents();
Cpu = new Cpu(this);
Memory = new Memory(this, appleIIe);
Keyboard = new Keyboard(this);
GamePort = new GamePort(this);
Cassette = new Cassette(this);
Speaker = new Speaker(this);
Video = new Video(this);
NoSlotClock = new NoSlotClock(this);
var emptySlot = new PeripheralCard(this);
Slot1 = emptySlot;
Slot2 = emptySlot;
Slot3 = emptySlot;
Slot4 = emptySlot;
Slot5 = emptySlot;
Slot6 = new DiskIIController(this, diskIIRom);
Slot7 = emptySlot;
Slots = new List<PeripheralCard> { null, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
Components = new List<MachineComponent> { Cpu, Memory, Keyboard, GamePort, Cassette, Speaker, Video, NoSlotClock, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
BootDiskII = Slots.OfType<DiskIIController>().Last();
}