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


C# IReadOnlyCollection.FirstOrDefault方法代码示例

本文整理汇总了C#中IReadOnlyCollection.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyCollection.FirstOrDefault方法的具体用法?C# IReadOnlyCollection.FirstOrDefault怎么用?C# IReadOnlyCollection.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IReadOnlyCollection的用法示例。


在下文中一共展示了IReadOnlyCollection.FirstOrDefault方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsIgnoredDecl

        public static bool IsIgnoredDecl(IReadOnlyCollection<string> ifStack, IReadOnlyCollection<Definition> defns)
        {
            foreach (var s in ifStack)
            {
                try
                {
                    Action<string, FunctionArgs> evalFunc = null;
                    Action<string, ParameterArgs> evalParam = null;

                    evalFunc = (name, args) =>
                    {
                        var def = defns.FirstOrDefault(d => d.Identifier == name && d.Arguments != null
                            && d.Arguments.Count == args.Parameters.Length);
                        if (def != null)
                        {
                            var e2 = new Expression(def.Replacement);

                            for (int i = 0; i < def.Arguments.Count; ++i)
                                e2.Parameters.Add(def.Arguments[i], args.Parameters[i].Evaluate());

                            e2.EvaluateFunction += new EvaluateFunctionHandler(evalFunc);
                            e2.EvaluateParameter += new EvaluateParameterHandler(evalParam);
                            args.Result = e2.Evaluate();
                        }
                    };

                    evalParam = (name, args) =>
                    {
                        var def = defns.FirstOrDefault(d => d.Identifier == name && d.Arguments == null);
                        if (def != null)
                        {
                            var e2 = new Expression(def.Replacement);
                            e2.EvaluateFunction += new EvaluateFunctionHandler(evalFunc);
                            e2.EvaluateParameter += new EvaluateParameterHandler(evalParam);
                            args.Result = e2.Evaluate();
                        }
                    };

                    var e = new Expression(s);
                    e.EvaluateFunction += new EvaluateFunctionHandler(evalFunc);
                    e.EvaluateParameter += new EvaluateParameterHandler(evalParam);

                    var result = e.Evaluate();
                    if (!Convert.ToBoolean(result))
                        return true;
                }
                catch
                {
                    // Empty catch, this is non-trivial, just print it out.
                }
            }

            return false;
        }
开发者ID:juntalis,项目名称:CHeaderGenerator,代码行数:54,代码来源:WriterExtensions.cs

示例2: AddDonations

 private static void AddDonations(IReadOnlyCollection<Tuple<string, int>> donations, IEnumerable<Domain.Person> persons)
 {
     foreach (var person in persons)
     {
         person.MemberOf.AddAmount(
             donations.FirstOrDefault(d => d.Item1 == person.Name)?.Item2 ?? 0);
     }
 }
开发者ID:onybo,项目名称:OrmDemo,代码行数:8,代码来源:Program.cs

示例3: FindMatchingPackageVersion

        /// <summary>
        /// Attempts to find the correct available version of a Nuget package.
        /// It will Try the version {Major, Minor, Build, Revision}, Then {Major, Minor, Build}, then {Major, Minor}, then {Major}
        /// </summary>
        /// <param name="packages"></param>
        /// <param name="assemblyVersion"></param>
        /// <returns></returns>
        private IPackage FindMatchingPackageVersion(IReadOnlyCollection<IPackage> packages, VersionInfo assemblyVersion)
        {
            Assert.ArgumentNotNull(packages, nameof(packages));
              Assert.ArgumentNotNull(assemblyVersion, nameof(assemblyVersion));

              var matchingPackage = packages.FirstOrDefault(package => package.Version.Version.Equals(assemblyVersion));
              if (matchingPackage != null)
              {
            return matchingPackage;
              }

              var major = assemblyVersion.Major;
              var minor = assemblyVersion.Minor;
              var build = assemblyVersion.Build;

              // Major, Minor, Build
              var buildVersionMatch = new Version(major, minor, build, 0);
              matchingPackage = packages.FirstOrDefault(package => package.Version.Version.Equals(buildVersionMatch));

              if (matchingPackage != null)
              {
            return matchingPackage;
              }

              // Major, Minor, BuildDigit1 (i.e 5.2.30706 becomes 5.2.3)
              var firstDigitBuildNumber = Math.Abs(build);
              while (firstDigitBuildNumber >= 10)
              {
            firstDigitBuildNumber /= 10;
              }

              var firstDigitiBuildVersionMatch = new Version(major, minor, firstDigitBuildNumber, 0);

              matchingPackage = packages.FirstOrDefault(package => package.Version.Version.Equals(firstDigitiBuildVersionMatch));

              if (matchingPackage != null)
              {
            return matchingPackage;
              }

              // Major, Minor
              var minorVersionMatch = new Version(major, minor, 0, 0);

              matchingPackage = packages.FirstOrDefault(package => package.Version.Version.Equals(minorVersionMatch));

              if (matchingPackage != null)
              {
            return matchingPackage;
              }

              // Major
              var majorVersionMatch = new Version(major, 0, 0, 0);

              matchingPackage = packages.FirstOrDefault(package => package.Version.Version.Equals(majorVersionMatch));

              // ReSharper disable once UseNullPropagation
              if (matchingPackage != null)
              {
            return matchingPackage;
              }

              return null;
        }
开发者ID:Sitecore,项目名称:Sitecore-Configurator,代码行数:70,代码来源:ThirdPartyPackageDiscoverer.cs

示例4: GetCommandDetails

 /// <summary>
 /// This method will return the command type with/without parameters to be executed
 /// </summary>
 /// <param name="commandTypes"></param>
 /// <param name="command"></param>
 /// <returns></returns>
 private static Dictionary<CommandType, object> GetCommandDetails(IReadOnlyCollection<CommandType> commandTypes, string command)
 {
     try
     {
         var resultDictionary = new Dictionary<CommandType, object>();
         if (commandTypes == null) return null;
         if (commandTypes.Count == 1)
         {
             var commandType = commandTypes.FirstOrDefault();
             switch (commandType)
             {
                 case CommandType.go:
                     {
                         resultDictionary.Add(commandType, CommandParametersManager.GetWebsiteNameForGoCommand(command.Split(' ').ToList()));
                         break;
                     }
                 case CommandType.go_to_tab:
                     {
                         resultDictionary.Add(commandType, CommandParametersManager.GetTabIndexForGoToTabCommand(command));
                         break;
                     }
                 case CommandType.move:
                     {
                         resultDictionary.Add(commandType, CommandParametersManager.GetxyValuesToMouseMoveCommand(command));
                         break;
                     }
                 default:
                     {
                         resultDictionary.Add(commandType, "");
                         break;
                     }
             }
         }
         return resultDictionary;
     }
     catch (Exception ex)
     {
         Log.ErrorLog(ex);
         throw;
     }
 }
开发者ID:prabash,项目名称:Voice-Based-Web-Browser,代码行数:47,代码来源:FirstLevelCategorization.cs

示例5: DirectRouteFactoryContext

        /// <summary>Initializes a new instance of the <see cref="DirectRouteFactoryContext"/></summary>
        /// <param name="areaPrefix">The route prefix, if any, defined by the area.</param>
        /// <param name="controllerPrefix">The route prefix, if any, defined by the controller.</param>
        /// <param name="actions">The action descriptors to which to create a route.</param>
        /// <param name="inlineConstraintResolver">The inline constraint resolver.</param>
        /// <param name="targetIsAction">
        /// A value indicating whether the route is configured at the action or controller level.
        /// </param>
        public DirectRouteFactoryContext(string areaPrefix, string controllerPrefix,
            IReadOnlyCollection<ActionDescriptor> actions, IInlineConstraintResolver inlineConstraintResolver,
            bool targetIsAction)
#endif
        {
            if (actions == null)
            {
                throw new ArgumentNullException("actions");
            }

            if (inlineConstraintResolver == null)
            {
                throw new ArgumentNullException("inlineConstraintResolver");
            }

#if ASPNETWEBAPI
            _prefix = prefix;
#else
            _areaPrefix = areaPrefix;
            _controllerPrefix = controllerPrefix;
#endif
            _actions = actions;
            _inlineConstraintResolver = inlineConstraintResolver;

            TActionDescriptor firstDescriptor = actions.FirstOrDefault();

            if (firstDescriptor != null)
            {
                _actionName = firstDescriptor.ActionName;
#if !ASPNETWEBAPI
                ControllerDescriptor controllerDescriptor = firstDescriptor.ControllerDescriptor;

                if (controllerDescriptor != null)
                {
                    _controllerName = controllerDescriptor.ControllerName;
                }
#endif
            }

            _targetIsAction = targetIsAction;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:49,代码来源:DirectRouteFactoryContext.cs

示例6: BuildDependencyTree

            private async Task BuildDependencyTree(Game game, List<string> dependencies,
                KeyValuePair<string, SixRepoModDto> repoContent,
                IReadOnlyCollection<CustomRepo> customRepos) {
                var name = repoContent.Key.ToLower();
                if (dependencies.Contains(name))
                    return;
                dependencies.Add(name);
                if (repoContent.Value.Dependencies == null)
                    return;

                var theC = repoContent.Value.Dependencies.ToDictionary(x => x.ToLower(),
                    x => customRepos.FirstOrDefault(r => r.HasMod(x)));

                var notFound = theC.Where(x => x.Value == null).Select(x => x.Key).ToList();
                if (notFound.Any())
                    await SynchronizeContent(game, notFound).ConfigureAwait(false);

                foreach (var d in repoContent.Value.Dependencies) {
                    var n = d.ToLower();
                    var repo = customRepos.FirstOrDefault(r => r.HasMod(d));
                    if (repo == null) {
                        var nc =
                            game.NetworkContent.FirstOrDefault(
                                x => x.PackageName.Equals(d, StringComparison.OrdinalIgnoreCase));
                        if (nc != null) {
                            var deps =
                                nc.GetRelatedContent()
                                    .Select(x => x.Content)
                                    .OfType<IHavePackageName>()
                                    .Select(x => x.PackageName)
                                    .Where(x => !dependencies.ContainsIgnoreCase(x))
                                    .ToArray();
                            // TODO: this does not take care of dependencies that actually exist then on the custom repo, and might have different deps setup than the official network counter parts..
                            // But the use case is very limited..
                            dependencies.AddRange(deps);
                        } else
                            dependencies.Add(n);
                    } else
                        await BuildDependencyTree(game, dependencies, repo.GetMod(d), customRepos).ConfigureAwait(false);
                }

                dependencies.Remove(name);
                dependencies.Add(name);
            }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:44,代码来源:NetworkContentSyncer.cs

示例7: HandleRepoContent

 private async Task<Content> HandleRepoContent(CollectionVersionDependencyModel x, Collection col,
     IReadOnlyCollection<CustomRepo> customRepos, Game game) {
     var repo = customRepos.FirstOrDefault(r => r.HasMod(x.Dependency));
     if (repo == null)
         return null;
     var repoContent = repo.GetMod(x.Dependency);
     var mod = new ModRepoContent(x.Dependency, col.GameId, repoContent.Value.GetVersionInfo());
     if (repoContent.Value.Dependencies != null)
         mod.Dependencies = await GetDependencyTree(repoContent, customRepos, game).ConfigureAwait(false);
     return mod;
 }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:11,代码来源:NetworkContentSyncer.cs

示例8: GetTestInitSetups

        private static IReadOnlyCollection<SetupsInfo> GetTestInitSetups(SyntaxNode testInitMethodDecl, IReadOnlyCollection<FieldDeclarationSyntax> declaredFields)
        {
            var result =  testInitMethodDecl.DescendantNodes()
                .OfType<ExpressionStatementSyntax>()
                .Select(x => new
                {
                    Expression = x,
                    Match = Regex.Match(x.ToString(), @"(.+)\s*\.(Setup){1}(Get){0,1}\(\s*(?<varName>\w+)\s*=>\s*\k<varName>\.(\w.+)((\(.*\){1})|'')\)\s*.Returns\((.+)\.Object\)")
                })
                .Where(x => x.Match.Success)
                .Select(x => new SetupsInfo
                {
                    Expression = x.Expression,
                    ParentField = declaredFields.FirstOrDefault(y => y.Declaration.Variables.Any(z => z.Identifier.Text == x.Match.Groups[1].Value.Trim())),
                    SetupIdentifierNode = x.Expression.DescendantNodes().OfType<MemberAccessExpressionSyntax>().FirstOrDefault(y => x.Match.Groups[4].Value.Trim() == y.Name.ToString() || x.Match.Groups[4].Value.Trim().StartsWith(y.Name.ToString() + "(")),
                    ReturnsField = declaredFields.FirstOrDefault(y => y.Declaration.Variables.Any(z => z.Identifier.Text == x.Match.Groups[7].Value.Trim())),
                })
                .ToArray();

            return result;
        }
开发者ID:ycherkes,项目名称:MockIt,代码行数:21,代码来源:TestSemanticHelper.cs

示例9: BulkGetHistoricPricesFromCarbon

        private static IReadOnlyDictionary<string, IReadOnlyDictionary<DateTime, double>> BulkGetHistoricPricesFromCarbon(ICarbonClient client, IReadOnlyCollection<AnalyticsBondStaticData> bondDatas,
            List<DateTime> dateSeries)
        {
            if (bondDatas.Count == 1 && dateSeries.Count > 1)
            {
                return BulkGetHistoricPricesFromCarbonOneBond(client, bondDatas.FirstOrDefault(), dateSeries);
            }

            var result = new ConcurrentDictionary<DateTime, IReadOnlyDictionary<string, double>>();
            Parallel.ForEach(dateSeries, date =>
            {
                if (date > DateTime.Today) return;
                var r = BulkGetHistoricPricesFromCarbon(client, bondDatas, date);
                result.AddOrUpdate(date, r, (time, pairs) => r);
            });

            var convertedResult = new Dictionary<string, Dictionary<DateTime, double>>();
            foreach (var kvp in result)
            {
                foreach (var kp in kvp.Value)
                {
                    if (convertedResult.ContainsKey(kp.Key))
                    {
                        convertedResult[kp.Key][kvp.Key] = kp.Value;
                    }
                    else
                    {
                        convertedResult[kp.Key] = new Dictionary<DateTime, double> { { kvp.Key, kp.Value } };
                    }
                }
            }
            return convertedResult.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as IReadOnlyDictionary<DateTime, double>);
        }
开发者ID:heimanhon,项目名称:researchwork,代码行数:33,代码来源:AnalyticsUtilities.cs

示例10: GetResourceTypes

        /// <summary>
        /// Get the resource type from the provided resourceProvider and the portion of the method
        /// URL path that comes after the resourceProvider section.
        /// </summary>
        /// <param name="resourceProvider"></param>
        /// <param name="methodPathAfterProvider"></param>
        /// <param name="createResourceMethodParameters"></param>
        /// <returns></returns>
        public static string[] GetResourceTypes(string resourceProvider, string methodPathAfterProvider, IReadOnlyCollection<Parameter> createResourceMethodParameters)
        {
            if (string.IsNullOrWhiteSpace(resourceProvider))
            {
                throw new ArgumentException("resourceProvider cannot be null or whitespace", "resourceProvider");
            }
            if (string.IsNullOrWhiteSpace(methodPathAfterProvider))
            {
                throw new ArgumentException("methodPathAfterProvider cannot be null or whitespace", "methodPathAfterProvider");
            }

            List<string> resourceTypes = new List<string>();
            resourceTypes.Add(resourceProvider);

            string[] pathSegments = methodPathAfterProvider.Split(new char[] { '/' });
            for (int i = 0; i < pathSegments.Length; i += 2)
            {
                string pathSegment = pathSegments[i];
                if (pathSegment.StartsWith("{", StringComparison.Ordinal) && pathSegment.EndsWith("}", StringComparison.Ordinal))
                {
                    string parameterName = pathSegment.Substring(1, pathSegment.Length - 2);
                    Parameter parameter = createResourceMethodParameters.FirstOrDefault(methodParameter => methodParameter.Name == parameterName);
                    if (parameter == null)
                    {
                        string errorMessage = string.Format(CultureInfo.CurrentCulture, "Found undefined parameter reference {0} in create resource method \"{1}/{2}/{3}\".", pathSegment, resourceMethodPrefix, resourceProvider, methodPathAfterProvider);
                        throw new ArgumentException(errorMessage, "createResourceMethodParameters");
                    }

                    if (parameter.Type == null)
                    {
                        string errorMessage = string.Format(CultureInfo.CurrentCulture, "Parameter reference {0} has no defined type.", pathSegment);
                        throw new ArgumentException(errorMessage, "createResourceMethodParameters");
                    }

                    EnumType parameterType = parameter.Type as EnumType;
                    if (parameterType == null)
                    {
                        string errorMessage = string.Format(CultureInfo.CurrentCulture, "Parameter reference {0} is defined as a type other than an EnumType: {1}", pathSegment, parameter.Type.GetType().Name);
                        throw new ArgumentException(errorMessage, "createResourceMethodParameters");
                    }

                    if (parameterType.Values == null || parameterType.Values.Count == 0)
                    {
                        string errorMessage = string.Format(CultureInfo.CurrentCulture, "Parameter reference {0} is defined as an EnumType, but it doesn't have any specified values.", pathSegment);
                        throw new ArgumentException(errorMessage, "createResourceMethodParameters");
                    }

                    List<string> newResourceTypes = new List<string>();
                    foreach (string resourceType in resourceTypes)
                    {
                        foreach (EnumValue parameterValue in parameterType.Values)
                        {
                            newResourceTypes.Add(string.Join("/", resourceType, parameterValue.Name));
                        }
                    }

                    resourceTypes = newResourceTypes;
                }
                else
                {
                    for (int j = 0; j < resourceTypes.Count; ++j)
                    {
                        resourceTypes[j] = string.Join("/", resourceTypes[j], pathSegment);
                    }
                }
            }

            return resourceTypes.ToArray();
        }
开发者ID:xingwu1,项目名称:autorest,代码行数:77,代码来源:ResourceSchemaParser.cs

示例11: GetDefaultLayout

        private static ILayoutInfo GetDefaultLayout(IReadOnlyCollection<ILayoutInfo> layoutList)
        {
            if (layoutList == null || layoutList.Count == 0)
                return null;

            var item =
                layoutList.FirstOrDefault(
                    l => (l.IsDefault ?? false) && (l.AccountId == Utils.CurrentUserAccountId || (l.AccountId == 0 && Utils.CurrentUserAccountId == -1)));
            if (item != null)
                return item;

            if (layoutList.Any(l => l.IsAdminDefault ?? false))
                return layoutList.First(l => l.IsAdminDefault ?? false);

            return layoutList.First();
        }
开发者ID:mparsin,项目名称:Elements,代码行数:16,代码来源:SearchUtils.cs

示例12: BuildDependencyTree

        static void BuildDependencyTree(List<string> dependencies, KeyValuePair<string, SixRepoModDto> repoContent,
            CustomRepo[] customRepos, IReadOnlyCollection<NetworkContent> content) {
            var name = repoContent.Key.ToLower();
            if (dependencies.Contains(name))
                return;
            dependencies.Add(name);
            if (repoContent.Value.Dependencies == null)
                return;

            foreach (var d in repoContent.Value.Dependencies) {
                var n = d.ToLower();
                var repo = customRepos.FirstOrDefault(r => r.HasMod(d));
                if (repo == null) {
                    var nc =
                        content.FirstOrDefault(x => x.PackageName.Equals(d, StringComparison.InvariantCultureIgnoreCase));
                    if (nc != null) {
                        var deps =
                            nc.GetRelatedContent()
                                .Select(x => x.Content)
                                .OfType<IHavePackageName>()
                                .Select(x => x.PackageName)
                                .Where(x => !dependencies.ContainsIgnoreCase(x))
                                .ToArray();
                        // TODO: this does not take care of dependencies that actually exist then on the custom repo, and might have different deps setup than the official network counter parts..
                        // But the use case is very limited..
                        dependencies.AddRange(deps);
                    } else
                        dependencies.Add(n);
                } else
                    BuildDependencyTree(dependencies, repo.GetMod(d), customRepos, content);
            }

            dependencies.Remove(name);
            dependencies.Add(name);
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:35,代码来源:NetworkContentSyncer.cs

示例13: ProcessLocalContent

 static void ProcessLocalContent(LocalContent localContent, IReadOnlyCollection<NetworkContent> contents) {
     var nc = contents.FirstOrDefault(x => x.PackageName.Equals(localContent.PackageName)) ??
              contents.Find(localContent.ContentId);
     if (nc == null)
         return;
     localContent.UpdateFrom(nc);
 }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:7,代码来源:NetworkContentSyncer.cs

示例14: AiaInfo

 public AiaInfo(IReadOnlyCollection<IHavePackageName> contentWithPackageNames) {
     const string allinarmaTp = "@AllInArmaTerrainPack";
     const string allinarmaTpLite = "@AllInArmaTerrainPackLite";
     const string cupTerrainCore = "@cup_terrains_core";
     const string cupTerrainMaps = "@cup_terrains_maps";
     const string a3mappack = "@A3Mp";
     Aia = contentWithPackageNames.FirstOrDefault(x => Matches(x.PackageName, allinarmaTp));
     A3Mp = contentWithPackageNames.FirstOrDefault(x => Matches(x.PackageName, a3mappack));
     AiaLite = contentWithPackageNames.FirstOrDefault(x => Matches(x.PackageName, allinarmaTpLite));
     Cup = contentWithPackageNames.FirstOrDefault(x => Matches(x.PackageName, cupTerrainCore));
     CupMaps = contentWithPackageNames.FirstOrDefault(x => Matches(x.PackageName, cupTerrainMaps));
     //var aiaSpecific = enabledMods.Contains(Aia) ? Aia : null;
     //var aiaSpecificLite = enabledMods.Contains(AiaLite) ? AiaLite : null;
 }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:14,代码来源:Arma3Game.cs


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