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


C# ImmutableArray.FirstOrDefault方法代码示例

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


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

示例1: FormatDiagnostics

        /// <summary>
        /// Helper method to format a <see cref="Diagnostic"/> into an easily readable string.
        /// </summary>
        /// <param name="analyzers">The analyzers that this verifier tests.</param>
        /// <param name="diagnostics">A collection of <see cref="Diagnostic"/>s to be formatted.</param>
        /// <returns>The <paramref name="diagnostics"/> formatted as a string.</returns>
        private static string FormatDiagnostics(ImmutableArray<DiagnosticAnalyzer> analyzers, params Diagnostic[] diagnostics)
        {
            var builder = new StringBuilder();
            for (int i = 0; i < diagnostics.Length; ++i)
            {
                var diagnosticsId = diagnostics[i].Id;

                builder.AppendLine("// " + diagnostics[i].ToString());

                var applicableAnalyzer = analyzers.FirstOrDefault(a => a.SupportedDiagnostics.Any(dd => dd.Id == diagnosticsId));
                if (applicableAnalyzer != null)
                {
                    var analyzerType = applicableAnalyzer.GetType();

                    var location = diagnostics[i].Location;
                    if (location == Location.None)
                    {
                        builder.AppendFormat("GetGlobalResult({0}.{1})", analyzerType.Name, diagnosticsId);
                    }
                    else
                    {
                        Assert.True(
                            location.IsInSource,
                            string.Format("Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata:\r\n", diagnostics[i]));

                        string resultMethodName = diagnostics[i].Location.SourceTree.FilePath.EndsWith(".cs") ? "GetCSharpResultAt" : "GetBasicResultAt";
                        var linePosition = diagnostics[i].Location.GetLineSpan().StartLinePosition;

                        builder.AppendFormat(
                            "{0}({1}, {2}, {3}.{4})",
                            resultMethodName,
                            linePosition.Line + 1,
                            linePosition.Character + 1,
                            analyzerType.Name,
                            diagnosticsId);
                    }

                    if (i != diagnostics.Length - 1)
                    {
                        builder.Append(',');
                    }

                    builder.AppendLine();
                }
            }

            return builder.ToString();
        }
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:54,代码来源:DiagnosticVerifier.cs

示例2: WithFilteredItems

 public Model WithFilteredItems(ImmutableArray<PresentationItem> filteredItems)
 {
     return With(filteredItems: filteredItems, selectedItem: filteredItems.FirstOrDefault());
 }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:4,代码来源:Model.cs

示例3: GetBestCompletionItemBasedOnMRU

            /// <summary>
            /// Given multiple possible chosen completion items, pick the one that has the
            /// best MRU index.
            /// </summary>
            private CompletionItem GetBestCompletionItemBasedOnMRU(
                ImmutableArray<CompletionItem> chosenItems, ImmutableArray<string> recentItems)
            {
                var bestItem = chosenItems.FirstOrDefault();
                for (int i = 1, n = chosenItems.Length; i < n; i++)
                {
                    var chosenItem = chosenItems[i];
                    var mruIndex1 = GetRecentItemIndex(recentItems, bestItem);
                    var mruIndex2 = GetRecentItemIndex(recentItems, chosenItem);

                    if (mruIndex2 < mruIndex1)
                    {
                        bestItem = chosenItem;
                    }
                }

                return bestItem;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:22,代码来源:Controller.Session_FilterModel.cs

示例4: CheckIfAnalyzerThrew

 /// <param name="diags">The compiler diagnostics at a given compilation.</param>
 /// <remarks>
 /// Todo: Remove/Update when https://github.com/dotnet/roslyn/issues/2580 is completed and there is
 /// an api to check for analyzer exceptions
 /// </remarks>
 private static void CheckIfAnalyzerThrew(ImmutableArray<Diagnostic> diags)
 {
     var exceptionAnalyzer = diags.FirstOrDefault(d => d.Id == "AD0001");
     if (exceptionAnalyzer != null) throw new Exception($"Analyzer threw. Details:\nMessage:{exceptionAnalyzer.GetMessage()}.");
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:10,代码来源:DiagnosticVerifier.Helper.cs

示例5: TryToBind

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bindings"></param>
        /// <param name="db"></param>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private static bool TryToBind(
            ImmutableArray<ShapeBinding> bindings,
            ImmutableArray<ShapeProperty> db,
            string propertyName,
            out string value)
        {
            foreach (var binding in bindings)
            {
                if (string.IsNullOrEmpty(binding.Property) || string.IsNullOrEmpty(binding.Path))
                    continue;

                if (binding.Property != propertyName)
                    continue;

                var result = db.FirstOrDefault(p => p.Name == binding.Path);
                if (result != null && result.Value != null)
                {
                    value =  result.Value.ToString();
                    return true;
                }
            }

            value = null;
            return false;
        }
开发者ID:monocraft,项目名称:Core2D,代码行数:33,代码来源:XText.cs

示例6: GetFirstMatchingNamespaceOrType

 private static INamespaceOrTypeSymbol GetFirstMatchingNamespaceOrType(ImmutableArray<ISymbol> candidateMembers)
 {
     return (INamespaceOrTypeSymbol)candidateMembers
         .FirstOrDefault(s =>
             s.Kind == SymbolKind.Namespace ||
             s.Kind == SymbolKind.NamedType);
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:SuppressMessageAttributeState.TargetSymbolResolver.cs

示例7: GetFirstMatchingNamedType

 private static INamedTypeSymbol GetFirstMatchingNamedType(ImmutableArray<ISymbol> candidateMembers, int arity)
 {
     return (INamedTypeSymbol)candidateMembers.FirstOrDefault(s =>
         s.Kind == SymbolKind.NamedType &&
         ((INamedTypeSymbol)s).Arity == arity);
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:6,代码来源:SuppressMessageAttributeState.TargetSymbolResolver.cs

示例8: WithFilteredItems

 public Model WithFilteredItems(ImmutableArray<PresentationItem> filteredItems)
 {
     return new Model(_disconnectedBufferGraph, OriginalList, TotalItems, filteredItems,
         filteredItems.FirstOrDefault(), CompletionItemFilters, FilterState, CompletionItemToFilterText, IsHardSelection, 
         IsUnique, UseSuggestionMode, SuggestionModeItem, DefaultSuggestionModeItem, 
         Trigger, CommitTrackingSpanEndPoint, DismissIfEmpty);
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:7,代码来源:Model.cs

示例9: GetBestCompletionItemBasedOnMRU

            /// <summary>
            /// Given multiple possible chosen completion items, pick the one that has the
            /// best MRU index.
            /// </summary>
            private CompletionItem GetBestCompletionItemBasedOnMRU(
                ImmutableArray<CompletionItem> chosenItems, ImmutableArray<string> recentItems)
            {
                if (chosenItems.Length == 0)
                {
                    return null;
                }

                // Try to find the chosen item has been most
                // recently used.
                var bestItem = chosenItems.FirstOrDefault();
                for (int i = 0, n = chosenItems.Length; i < n; i++)
                {
                    var chosenItem = chosenItems[i];
                    var mruIndex1 = GetRecentItemIndex(recentItems, bestItem);
                    var mruIndex2 = GetRecentItemIndex(recentItems, chosenItem);

                    if (mruIndex2 < mruIndex1)
                    {
                        bestItem = chosenItem;
                    }
                }

                // If our best item appeared in the MRU list, use it
                if (GetRecentItemIndex(recentItems, bestItem) <= 0)
                {
                    return bestItem;
                }

                // Otherwise use the chosen item that has the highest
                // matchPriority.
                for (int i = 1, n = chosenItems.Length; i < n; i++)
                {
                    var chosenItem = chosenItems[i];
                    var bestItemPriority = bestItem.Rules.MatchPriority;
                    var currentItemPriority = chosenItem.Rules.MatchPriority;

                    if (currentItemPriority > bestItemPriority)
                    {
                        bestItem = chosenItem;
                    }
                }

                return bestItem;
            }
开发者ID:jkotas,项目名称:roslyn,代码行数:49,代码来源:Controller.Session_FilterModel.cs

示例10: TryToBind

        /// <summary>
        /// Try binding properties array to one of <see cref="XText"/> shape properties.
        /// </summary>
        /// <param name="db">The properties database used for binding.</param>
        /// <param name="propertyName">The target property name.</param>
        /// <param name="value">The string bound to properties.</param>
        /// <returns>True if binding was successful.</returns>
        private static bool TryToBind(ImmutableArray<XProperty> db, string propertyName, out string value)
        {
            if (string.IsNullOrEmpty(propertyName) || db == null)
            {
                value = null;
                return false;
            }

            var result = db.FirstOrDefault(p => p.Name == propertyName);
            if (result != null && result.Value != null)
            {
                value = result.Value.ToString();
                return true;
            }

            value = null;
            return false;
        }
开发者ID:Core2D,项目名称:Core2D,代码行数:25,代码来源:XText.cs


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