当前位置: 首页>>代码示例>>C#>>正文


C# ICollection.FirstOrDefault方法代码示例

本文整理汇总了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;
 }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:27,代码来源:SurroundingNodeTraversal.cs

示例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 });
        }
开发者ID:maksym-fedorov-epam,项目名称:pip-statuses,代码行数:7,代码来源:ReplicationFactory.cs

示例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
            }
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:28,代码来源:CompareSequences.cs

示例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;
        }
开发者ID:USAID-DELIVER-PROJECT,项目名称:ethiopia-hcmis-warehouse,代码行数:32,代码来源:RequestValidation.cs

示例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;
        }
开发者ID:sergeu90,项目名称:OurMemory,代码行数:7,代码来源:CustomMultipartFileStreamProvider.cs

示例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;
        }
开发者ID:goitsk,项目名称:NuGetGallery,代码行数:30,代码来源:LdapService.cs

示例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;
        }
开发者ID:sirrocco,项目名称:SqlScriptRunner,代码行数:33,代码来源:FileSynchronizer.cs

示例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);
        }
开发者ID:pwibeck,项目名称:InstallerVerificationFramework,代码行数:30,代码来源:StartMenuCheck.cs

示例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());
        }
开发者ID:tu-tran,项目名称:SubSearch,代码行数:16,代码来源:SilentView.cs

示例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];
         
     }
 }
开发者ID:GorshkovDmitry,项目名称:sortablejs,代码行数:9,代码来源:DefaultController.cs

示例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"));
        }
开发者ID:pietervp,项目名称:Hop,代码行数:18,代码来源:HopUpdateTests.cs

示例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);
            }
        }
开发者ID:roadrunner75,项目名称:dbschemareader,代码行数:56,代码来源:ComparePackages.cs

示例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)));
        }
开发者ID:someaccountidontuse,项目名称:SsoWsFederation,代码行数:11,代码来源:SignOutController.cs

示例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);
     }
 }
开发者ID:JoeGilkey,项目名称:RadioLog,代码行数:11,代码来源:RollCallService.cs

示例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;
        }
开发者ID:Havret,项目名称:CeneoETL,代码行数:11,代码来源:CeneoProductProvider.cs


注:本文中的ICollection.FirstOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。