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


C# ImmutableDictionary.TryGetValue方法代码示例

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


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

示例1: ChangeDependencies

        /// <summary>
        /// Change the NuGet dependencies in the file to match the new packages.
        /// </summary>
        internal static bool ChangeDependencies(string filePath, ImmutableDictionary<NuGetPackage, NuGetPackage> changeMap)
        {
            var obj = JObject.Parse(File.ReadAllText(filePath), new JsonLoadSettings() { CommentHandling = CommentHandling.Load });
            var dependencies = (JObject)obj["dependencies"];
            if (dependencies == null)
            {
                return false;
            }

            var changed = false;
            foreach (var prop in dependencies.Properties())
            {
                var currentPackage = ParseDependency(prop);
                NuGetPackage newPackage;
                if (!changeMap.TryGetValue(currentPackage, out newPackage))
                {
                    continue;
                }

                ChangeDependency(prop, newPackage.Version);
                changed = true;
            }

            if (!changed)
            {
                return false;
            }

            var data = JsonConvert.SerializeObject(obj, Formatting.Indented);
            File.WriteAllText(filePath, data);
            return true;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:35,代码来源:ProjectJsonUtil.cs

示例2: GetRemoveSet

        /// <summary>
        /// Collects all the trees #load'ed by <paramref name="oldTree"/> (as well as
        /// <paramref name="oldTree"/> itself) and populates <paramref name="removeSet"/>
        /// with all the trees that are safe to remove (not #load'ed by any other tree).
        /// </summary>
        private static void GetRemoveSet(
            SyntaxTree oldTree,
            bool includeLoadedTrees,
            ImmutableArray<SyntaxTree> syntaxTrees,
            ImmutableDictionary<SyntaxTree, int> syntaxTreeOrdinalMap,
            ImmutableDictionary<SyntaxTree, ImmutableArray<LoadDirective>> loadDirectiveMap,
            ImmutableDictionary<string, SyntaxTree> loadedSyntaxTreeMap,
            HashSet<SyntaxTree> removeSet,
            out int totalReferencedTreeCount,
            out ImmutableArray<LoadDirective> oldLoadDirectives)
        {
            if (includeLoadedTrees && loadDirectiveMap.TryGetValue(oldTree, out oldLoadDirectives))
            {
                Debug.Assert(!oldLoadDirectives.IsEmpty);
                GetRemoveSetForLoadedTrees(oldLoadDirectives, loadDirectiveMap, loadedSyntaxTreeMap, removeSet);
            }

            removeSet.Add(oldTree);
            totalReferencedTreeCount = removeSet.Count;

            // Check subsequent trees to see if they #load any of the trees we're about
            // to remove.  We don't want to remove a tree until the last external tree
            // that depends on it is removed.
            if (removeSet.Count > 1)
            {
                var ordinal = syntaxTreeOrdinalMap[oldTree];
                for (int i = ordinal + 1; i < syntaxTrees.Length; i++)
                {
                    var tree = syntaxTrees[i];
                    ImmutableArray<LoadDirective> loadDirectives;
                    if (loadDirectiveMap.TryGetValue(tree, out loadDirectives))
                    {
                        Debug.Assert(!loadDirectives.IsEmpty);
                        foreach (var directive in loadDirectives)
                        {
                            var loadedTree = loadedSyntaxTreeMap[directive.ResolvedPath];
                            if (removeSet.Contains(loadedTree))
                            {
                                removeSet.Remove(loadedTree);
                            }
                        }
                    }
                }
            }
        }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:50,代码来源:SyntaxAndDeclarationManager.cs

示例3: UpdateDiagnosticAnalyzerToPackageNameMap

        private void UpdateDiagnosticAnalyzerToPackageNameMap(
            ImmutableDictionary<string, string> nameMap,
            AnalyzerReference reference,
            ImmutableArray<DiagnosticAnalyzer> analyzers)
        {
            var fileReference = reference as AnalyzerFileReference;
            if (fileReference == null)
            {
                return;
            }

            string name;
            if (!nameMap.TryGetValue(fileReference.FullPath, out name))
            {
                return;
            }

            foreach (var analyzer in analyzers)
            {
                ImmutableInterlocked.GetOrAdd(ref _hostDiagnosticAnalyzerPackageNameMap, analyzer, _ => name);
            }
        }
开发者ID:hbarve1,项目名称:roslyn,代码行数:22,代码来源:HostAnalyzerManager.cs

示例4: ItemIsFilteredOut

            private bool ItemIsFilteredOut(
                CompletionItem item,
                ImmutableDictionary<CompletionItemFilter, bool> filterState)
            {
                if (filterState == null)
                {
                    // No filtering.  The item is not filtered out.
                    return false;
                }

                foreach (var filter in CompletionItemFilter.AllFilters)
                {
                    // only consider filters that match the item
                    var matches = filter.Matches(item);
                    if (matches)
                    {
                        // if the specific filter is enabled then it is not filtered out
                        bool enabled;
                        if (filterState.TryGetValue(filter, out enabled) && enabled)
                        {
                            return false;
                        }
                    }
                }

                // The item was filtered out.
                return true;
            }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:28,代码来源:Controller.Session_FilterModel.cs

示例5: TryGetLoadedSyntaxTree

        private static bool TryGetLoadedSyntaxTree(ImmutableDictionary<string, SyntaxTree> loadedSyntaxTreeMap, LoadDirective directive, out SyntaxTree loadedTree)
        {
            if (loadedSyntaxTreeMap.TryGetValue(directive.ResolvedPath, out loadedTree))
            {
                return true;
            }

            // If we don't have a tree for this directive, there should be errors.
            Debug.Assert(directive.Diagnostics.HasAnyErrors());

            return false;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:12,代码来源:SyntaxAndDeclarationManager.cs

示例6: GetConstants

        private static void GetConstants(
            ArrayBuilder<LocalSymbol> builder,
            MethodSymbol method,
            IEnumerable<ISymUnmanagedScope> scopes,
            MetadataDecoder metadataDecoder,
            ImmutableDictionary<string, ImmutableArray<bool>> dynamicLocalConstantMap,
            SourceAssemblySymbol containingAssembly)
        {
            foreach (var scope in scopes)
            {
                foreach (var constant in scope.GetConstants())
                {
                    string name = constant.GetName();
                    object rawValue = constant.GetValue();
                    var signature = constant.GetSignature();

                    var info = metadataDecoder.GetLocalInfo(signature);
                    Debug.Assert(!info.IsByRef);
                    Debug.Assert(!info.IsPinned);
                    var type = info.Type;

                    var constantValue = PdbHelpers.GetConstantValue(type.EnumUnderlyingType(), rawValue);

                    ImmutableArray<bool> dynamicFlags;
                    if (dynamicLocalConstantMap != null && dynamicLocalConstantMap.TryGetValue(name, out dynamicFlags))
                    {
                        type = DynamicTypeDecoder.TransformTypeWithoutCustomModifierFlags(
                            type,
                            containingAssembly,
                            RefKind.None,
                            dynamicFlags);
                    }

                    builder.Add(new EELocalConstantSymbol(method, name, type, constantValue));
                }
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:37,代码来源:EvaluationContext.cs

示例7: DiffStateSets

                private ImmutableArray<StateSet> DiffStateSets(
                    IEnumerable<AnalyzerReference> references,
                    ImmutableDictionary<object, ImmutableArray<DiagnosticAnalyzer>> mapPerReference,
                    ImmutableDictionary<DiagnosticAnalyzer, StateSet> map)
                {
                    if (mapPerReference.Count == 0 || map.Count == 0)
                    {
                        // nothing to diff
                        return ImmutableArray<StateSet>.Empty;
                    }

                    var builder = ImmutableArray.CreateBuilder<StateSet>();
                    foreach (var reference in references)
                    {
                        var referenceIdentity = _owner.AnalyzerManager.GetAnalyzerReferenceIdentity(reference);

                        // check duplication
                        ImmutableArray<DiagnosticAnalyzer> analyzers;
                        if (!mapPerReference.TryGetValue(referenceIdentity, out analyzers))
                        {
                            continue;
                        }

                        // okay, this is real reference. get stateset
                        foreach (var analyzer in analyzers)
                        {
                            StateSet set;
                            if (!map.TryGetValue(analyzer, out set))
                            {
                                continue;
                            }

                            builder.Add(set);
                        }
                    }

                    return builder.ToImmutable();
                }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:38,代码来源:DiagnosticIncrementalAnalyzer.StateManager.ProjectStates.cs

示例8: UpdateSyntaxTreesAndOrdinalMapOnly

        private static void UpdateSyntaxTreesAndOrdinalMapOnly(
            ArrayBuilder<SyntaxTree> treesBuilder,
            SyntaxTree tree,
            IDictionary<SyntaxTree, int> ordinalMapBuilder,
            ImmutableDictionary<SyntaxTree, ImmutableArray<LoadDirective>> loadDirectiveMap,
            ImmutableDictionary<string, SyntaxTree> loadedSyntaxTreeMap)
        {
            var sourceCodeKind = tree.Options.Kind;
            if (sourceCodeKind == SourceCodeKind.Script)
            {
                ImmutableArray<LoadDirective> loadDirectives;
                if (loadDirectiveMap.TryGetValue(tree, out loadDirectives))
                {
                    Debug.Assert(!loadDirectives.IsEmpty);
                    foreach (var directive in loadDirectives)
                    {
                        var resolvedPath = directive.ResolvedPath;
                        Debug.Assert((resolvedPath != null) || !directive.Diagnostics.IsEmpty);
                        if (resolvedPath != null)
                        {
                            var loadedTree = loadedSyntaxTreeMap[directive.ResolvedPath];
                            UpdateSyntaxTreesAndOrdinalMapOnly(
                                treesBuilder,
                                loadedTree,
                                ordinalMapBuilder,
                                loadDirectiveMap,
                                loadedSyntaxTreeMap);
                        }

                        treesBuilder.Add(tree);

                        ordinalMapBuilder.Add(tree, ordinalMapBuilder.Count);
                    }
                }
            }

            treesBuilder.Add(tree);

            ordinalMapBuilder.Add(tree, ordinalMapBuilder.Count);
        }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:40,代码来源:SyntaxAndDeclarationManager.cs

示例9: ChangeAllCore

        /// <summary>
        /// Change the repo to respect the new version for the specified set of NuGet packages
        /// </summary>
        private void ChangeAllCore(ImmutableDictionary<NuGetPackage, NuGetPackage> changeMap)
        {
            ChangeProjectJsonFiles(changeMap);

            // Calculate the new set of packages based on the changed information.
            var list = new List<NuGetPackage>();
            foreach (var cur in _repoData.FloatingBuildPackages)
            {
                NuGetPackage newPackage;
                if (changeMap.TryGetValue(cur, out newPackage))
                {
                    list.Add(newPackage);
                }
                else
                {
                    list.Add(cur);
                }
            }

            ChangeGeneratedFiles(list);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:24,代码来源:ChangeCommand.cs

示例10: AddDiagnosticForSymbolIfNeeded

            private static void AddDiagnosticForSymbolIfNeeded(ISymbol targetSymbol, Diagnostic diagnostic, ImmutableDictionary<ISymbol, List<Diagnostic>>.Builder diagnosticsMapBuilder)
            {
                if (diagnostic.IsSuppressed)
                {
                    return;
                }

                if (!diagnosticsMapBuilder.TryGetValue(targetSymbol, out var diagnosticsForSymbol))
                {
                    diagnosticsForSymbol = new List<Diagnostic>();
                    diagnosticsMapBuilder.Add(targetSymbol, diagnosticsForSymbol);
                }

                diagnosticsForSymbol.Add(diagnostic);
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:15,代码来源:AbstractSuppressionCodeFixProvider.GlobalSuppressMessageFixAllCodeAction.cs

示例11: GetResultOrEmpty

        private static DiagnosticAnalysisResult GetResultOrEmpty(ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult> map, DiagnosticAnalyzer analyzer, ProjectId projectId, VersionStamp version)
        {
            if (map.TryGetValue(analyzer, out var result))
            {
                return result;
            }

            return new DiagnosticAnalysisResult(projectId, version);
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:9,代码来源:DiagnosticIncrementalAnalyzer.cs

示例12: ExecuteCompilationActionsAsync

        private async Task ExecuteCompilationActionsAsync(
            ImmutableDictionary<DiagnosticAnalyzer, ImmutableArray<CompilationAnalyzerAction>> compilationActionsMap,
            CompilationEvent compilationEvent,
            AnalysisScope analysisScope,
            AnalysisState analysisStateOpt,
            CancellationToken cancellationToken)
        {
            Debug.Assert(compilationEvent is CompilationStartedEvent || compilationEvent is CompilationCompletedEvent);

            try
            {
                foreach (var analyzer in analysisScope.Analyzers)
                {
                    ImmutableArray<CompilationAnalyzerAction> compilationActions;
                    if (compilationActionsMap.TryGetValue(analyzer, out compilationActions))
                    {
                        await analyzerExecutor.ExecuteCompilationActionsAsync(compilationActions, analyzer, compilationEvent, analysisScope, analysisStateOpt).ConfigureAwait(false);
                    }
                    else if (analysisStateOpt != null)
                    {
                        await analysisStateOpt.MarkEventCompleteAsync(compilationEvent, analyzer, cancellationToken).ConfigureAwait(false);
                    }
                }
            }
            finally
            {
                compilationEvent.FlushCache();
            }
        }
开发者ID:jeffanders,项目名称:roslyn,代码行数:29,代码来源:AnalyzerDriver.cs

示例13: AddExplicitSymbolStates

            private static void AddExplicitSymbolStates(ImmutableDictionary<string, Tristate>.Builder symbolStates, IEnumerable<string> symbols, Tristate explicitState)
            {
                if (symbols == null)
                {
                    return;
                }

                foreach (var symbol in symbols)
                {
                    Tristate state;
                    if (symbolStates.TryGetValue(symbol, out state))
                    {
                        if (state == explicitState)
                        {
                            throw new ArgumentException(
                                string.Format("Symbol '{0}' appears in the {1} list multiple times",
                                    symbol, GetStateString(explicitState)));
                        }
                        else
                        {
                            throw new ArgumentException(
                                string.Format("Symbol '{0}' cannot be both {1} and {2}",
                                    symbol, GetStateString(state), GetStateString(explicitState)));
                        }
                    }
                    else
                    {
                        symbolStates[symbol] = explicitState;
                    }
                }
            }
开发者ID:chuck-mitchell,项目名称:codeformatter,代码行数:31,代码来源:AnalysisEngine.Options.cs

示例14: GetRemoveSetForLoadedTrees

        private static void GetRemoveSetForLoadedTrees(
            ImmutableArray<LoadDirective> loadDirectives,
            ImmutableDictionary<SyntaxTree, ImmutableArray<LoadDirective>> loadDirectiveMap,
            ImmutableDictionary<string, SyntaxTree> loadedSyntaxTreeMap,
            HashSet<SyntaxTree> removeSet)
        {
            foreach (var directive in loadDirectives)
            {
                if (directive.ResolvedPath != null)
                {
                    var loadedTree = loadedSyntaxTreeMap[directive.ResolvedPath];
                    ImmutableArray<LoadDirective> nestedLoadDirectives;
                    if (loadDirectiveMap.TryGetValue(loadedTree, out nestedLoadDirectives))
                    {
                        Debug.Assert(!nestedLoadDirectives.IsEmpty);
                        GetRemoveSetForLoadedTrees(nestedLoadDirectives, loadDirectiveMap, loadedSyntaxTreeMap, removeSet);
                    }

                    removeSet.Add(loadedTree);
                }
            }
        }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:22,代码来源:SyntaxAndDeclarationManager.cs

示例15: IsLoadedSyntaxTree

 internal static bool IsLoadedSyntaxTree(SyntaxTree tree, ImmutableDictionary<string, SyntaxTree> loadedSyntaxTreeMap)
 {
     SyntaxTree loadedTree;
     return loadedSyntaxTreeMap.TryGetValue(tree.FilePath, out loadedTree) && (tree == loadedTree);
 }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:5,代码来源:SyntaxAndDeclarationManager.cs


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