本文整理汇总了C#中ICollection.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.FirstOrDefault方法的具体用法?C# ICollection.FirstOrDefault怎么用?C# ICollection.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.FirstOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUnionKeys
public static HashSet<string> GetUnionKeys(
this ICollection<CstNode> nodes, ICollection<SelectedFragment> fragments,
FeatureExtractor extractor) {
var commonKeys = new HashSet<string>();
var usedRangeCount = 0;
if (nodes.Count > 0) {
var root = nodes.First().AncestorsAndSelf().Last();
foreach (var node in nodes) {
IEnumerable<CstNode> surroundingNodes;
CstNode outermostNode = null;
var fragment = fragments
.FirstOrDefault(f => node.AncestorWithSingleChild() == f.Node);
if (fragment != null) {
surroundingNodes = fragment.SurroundingRange.FindOverlappedNodes(root);
outermostNode = fragment.SurroundingRange.FindInnermostNode(root);
usedRangeCount++;
} else {
surroundingNodes = node.DescendantsAndSelf();
}
var keys = node.GetSurroundingPaths(
surroundingNodes.ToHashSet(), extractor, outermostNode);
commonKeys.UnionWith(keys);
}
}
Console.WriteLine("#Used Ranges: " + usedRangeCount);
return commonKeys;
}
示例2: MigrateCompositeContent
private static void MigrateCompositeContent(ICollection<ContentSegment> source, ICollection<ContentSegment> target)
{
var segment = source.FirstOrDefault(x => x.Type == ContentSegmentType.Text);
if (segment != null)
target.Add(new ContentSegment { Type = segment.Type, Text = segment.Text });
}
示例3: Execute
public void Execute(ICollection<DatabaseSequence> baseSequences, ICollection<DatabaseSequence> compareSequences)
{
//find new sequences (in compare, but not in base)
foreach (var sequence in compareSequences)
{
var name = sequence.Name;
var schema = sequence.SchemaOwner;
var match = baseSequences.FirstOrDefault(t => t.Name == name && t.SchemaOwner == schema);
if (match != null) continue;
CreateResult(ResultType.Add, sequence, "-- NEW SEQUENCE " + sequence.Name + Environment.NewLine +
_writer.AddSequence(sequence));
}
//find dropped and existing sequence
foreach (var sequence in baseSequences)
{
var name = sequence.Name;
var schema = sequence.SchemaOwner;
var match = compareSequences.FirstOrDefault(t => t.Name == name && t.SchemaOwner == schema);
if (match == null)
{
CreateResult(ResultType.Delete, sequence, "-- DROP SEQUENCE " + sequence.Name + Environment.NewLine +
_writer.DropSequence(sequence));
}
//we could alter the sequence, but it's rare you'd ever want to do this
}
}
示例4: CheckSplit
public bool CheckSplit(ICollection<RequestDetail> requestDetails)
{
var result =
requestDetails.GroupBy(
rd =>
new
{
rd.Item.ItemID,
rd.Unit.UnitID,
rd.ActivityGroup,
rd.Manufacturer,
rd.physicalStore,
rd.ExpiryDate
}, (key, group) =>
new
{
itemID = key.ItemID,
unitID = key.UnitID,
value = @group.Count(),
requestDetailID = group.Max(s => s.RequestDetailId)
}).Where(s => s.value > 1).ToList();
if (!result.Any())
{
return true;
}
foreach (var requestInfo in result)
{
Errors.Add(new RequestDetailError(RequestErrorType.DuplicateRequestDetail) { RequestDetail = requestDetails.FirstOrDefault(s => s.RequestDetailId == requestInfo.requestDetailID) });
}
return false;
}
示例5: GetNameHeaderValue
private static string GetNameHeaderValue(ICollection<NameValueHeaderValue> headerValues, string name)
{
var nameValueHeader = headerValues.FirstOrDefault(
x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
return nameValueHeader != null ? nameValueHeader.Value : null;
}
示例6: ValidateCredentials
public bool ValidateCredentials(ICollection<Credential> credentials, string password, out Credential matched)
{
var ldapCred = credentials.FirstOrDefault(c => c.Type == CredentialType_LdapUser);
matched = ldapCred;
if (ldapCred != null)
{
try
{
LdapConnection connection = new LdapConnection(this.Configuration.Server);
connection.SessionOptions.SecureSocketLayer = true;
connection.SessionOptions.VerifyServerCertificate = (ldapConnection, certificate) =>
{
return true;
};
connection.AuthType = AuthType.Negotiate;
NetworkCredential credential = new NetworkCredential(ldapCred.Value, password);
connection.Credential = credential;
connection.Bind();
return true;
}
catch (Exception)
{
return false;
}
}
return false;
}
示例7: SyncFileCollectionFromPath
public bool SyncFileCollectionFromPath(ICollection<SiqualFile> files, DatabaseServer server, Project project)
{
string folderPath = project.FolderPath;
if (!Directory.Exists(folderPath))
return false;
string[] filePaths = Directory.GetFiles(folderPath, "*.sql", SearchOption.AllDirectories);
IList<SiqualFile> filesRemovedFromPath = new List<SiqualFile>();
foreach (SiqualFile file in files)
{
if (filePaths.FirstOrDefault(x => x == file.FullFilePath) != null) continue;
filesRemovedFromPath.Add(file);
_filesChanged = true;
}
foreach (string filePath in filePaths)
{
if (files.FirstOrDefault(x => x.FullFilePath == filePath) != null) continue;
files.Add(new SiqualFile(filePath, server, project));
_filesChanged = true;
}
foreach (SiqualFile fileToRemove in filesRemovedFromPath)
{
files.Remove(fileToRemove);
}
return _filesChanged;
}
示例8: DoCheck
public override CheckResult DoCheck(BaseTestData data, ICollection<FileChange> fileChanges, ICollection<Registryhange> registryChanges)
{
if (!VerifyIfCorrectTestData(data))
{
return CheckResult.NotCheckDone();
}
var startMenuData = data as StartMenuData;
var path = startMenuData.AllUsers ? GetAllUsersMenuFolder() : Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
// To get the program folder
var dirInfo = new DirectoryInfo(path);
path = Path.Combine(path, dirInfo.GetDirectories()[0].Name);
path = Path.Combine(path, startMenuData.Name + ".lnk");
// Find registry GlobalAssocChangedCounter key that is updated when creating a startmenu
var globalAssocChangedCounterKey = @"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer";
if (Environment.Is64BitOperatingSystem)
{
globalAssocChangedCounterKey = @"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer";
}
var registryChange = registryChanges.FirstOrDefault(x => string.Equals(x.Key, globalAssocChangedCounterKey, StringComparison.InvariantCultureIgnoreCase) &&
x.ValueName == "GlobalAssocChangedCounter" &&
x.Type == RegistryChangeType.SetValue);
var fileChange = fileChanges.FirstOrDefault(x => x.Path == path);
return startMenuData.Exist ? CheckDataIfStartMenuIsExpectedToExist(fileChanges, registryChanges, fileChange, startMenuData, registryChange) :
CheckDataIfStartMenuIsExpectedToNotExist(fileChanges, registryChanges, fileChange, startMenuData, registryChange);
}
示例9: GetSelection
/// <summary>
/// Gets the selection.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="title">The title.</param>
/// <param name="status">The status.</param>
/// <returns>The query result.</returns>
public override QueryResult<ItemData> GetSelection(ICollection<ItemData> data, string title, string status)
{
if (data == null || !data.Any())
{
return new QueryResult<ItemData>(Status.Failure, null);
}
return new QueryResult<ItemData>(Status.Success, data.FirstOrDefault());
}
示例10: SortFiles
public static void SortFiles(ICollection<PathFile> files, IList<int> modifiedOrder, IList<int> originalPositions)
{
for (var i = 0; i < files.Count; i++)
{
var file = files.FirstOrDefault(h => h.FileID == modifiedOrder[i]);
file.Position = originalPositions[i];
}
}
示例11: UpdateMultipleEntitiesThenReadAndUpdatesSucces
public void UpdateMultipleEntitiesThenReadAndUpdatesSucces()
{
var random = new Random();
foreach (var beer in Beers)
{
beer.Name = random.Next(0, 100) + " Multiple ";
}
GetSqlConnection().Hop().Update(Beers);
Beers = GetSqlConnection().Hop().Read(Beers).ToList();
Assert.IsNotNull(Beers);
Assert.IsNotNull(Beers.FirstOrDefault());
Assert.IsFalse(Beers.Any(x=> x.Name == "11"));
Assert.IsTrue(Beers.FirstOrDefault().Name.Contains("Multiple"));
}
示例12: Execute
public void Execute(ICollection<DatabasePackage> basePackages, ICollection<DatabasePackage> comparePackages)
{
bool first = false;
//find new packages (in compare, but not in base)
foreach (var package in comparePackages)
{
var name = package.Name;
var schema = package.SchemaOwner;
var match = basePackages.FirstOrDefault(t => t.Name == name && t.SchemaOwner == schema);
if (match != null) continue;
var script = string.Empty;
if (!first)
{
first = true;
//CREATE PACKAGE cannot be combined with other statements in a batch,
//so be preceeded by and terminate with a "/"
if (_results.Count > 0) script += _writer.RunStatements() + Environment.NewLine;
}
script += "-- NEW PACKAGE " + package.Name + Environment.NewLine +
_writer.AddPackage(package);
CreateResult(ResultType.Add, package, script);
}
//find dropped and existing packages
foreach (var package in basePackages)
{
var name = package.Name;
var schema = package.SchemaOwner;
var match = comparePackages.FirstOrDefault(t => t.Name == name && t.SchemaOwner == schema);
if (match == null)
{
CreateResult(ResultType.Delete, package, "-- DROP PACKAGE " + package.Name + Environment.NewLine +
_writer.DropPackage(package));
continue;
}
if (package.Body == match.Body && package.Definition == match.Definition) continue;
var script = string.Empty;
if (!first)
{
first = true;
//CREATE PACKAGE cannot be combined with other statements in a batch,
//so be preceeded by and terminate with a "/"
if (_results.Count > 0) script += _writer.RunStatements() + Environment.NewLine;
}
//different package
script += "-- ALTER PACKAGE " + package.Name + Environment.NewLine;
//we rely on CREATE OR REPLACE here (no drop!)
script += _writer.AddPackage(match);
CreateResult(ResultType.Delete, package, script);
}
}
示例13: RemoveTheRpThatSignedOutFromRealmsToSignOut
private static void RemoveTheRpThatSignedOutFromRealmsToSignOut(
SignOutRequestMessage signOutRequestMessage,
ICollection<string> realmsToSignOut)
{
if (string.IsNullOrWhiteSpace(signOutRequestMessage.Reply))
{
return;
}
realmsToSignOut.Remove(realmsToSignOut.FirstOrDefault(s => signOutRequestMessage.Reply.Contains(s)));
}
示例14: AddToList
private void AddToList(RollCallItem rci, ICollection<RollCallItem> rciList)
{
if (!_firegroundEnabled)
return;
if (rci == null || rciList == null)
return;
if (rciList.FirstOrDefault(r => r.SignalingLookupKey == rci.SignalingLookupKey) == null)
{
rciList.Add(rci);
}
}
示例15: GetProductBrand
private string GetProductBrand(ICollection<string> productProperties)
{
var productBrand = productProperties.FirstOrDefault(x => x.StartsWith(BrandIdentifier));
if (productBrand != null)
{
return productBrand.Substring(BrandIdentifier.Length);
}
return null;
}