• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ConditionalWeakTable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ConditionalWeakTable的典型用法代码示例。如果您正苦于以下问题:C# ConditionalWeakTable类的具体用法?C# ConditionalWeakTable怎么用?C# ConditionalWeakTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConditionalWeakTable类属于命名空间,在下文中一共展示了ConditionalWeakTable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SearchBoxProperties

		static SearchBoxProperties()
		{
			_suggestionRequestedEventHandlers = new ConditionalWeakTable<SearchBox, TypedEventHandler<SearchBox, SearchBoxSuggestionsRequestedEventArgs>>();
			_resultSuggestionChosenEventHandlers = new ConditionalWeakTable<SearchBox, TypedEventHandler<SearchBox, SearchBoxResultSuggestionChosenEventArgs>>();
			_dataContextChangedEventHandlers = new ConditionalWeakTable<SearchBox, TypedEventHandler<FrameworkElement, DataContextChangedEventArgs>>();
			_querySubmittedCommandEventHandlers = new ConditionalWeakTable<SearchBox, TypedEventHandler<SearchBox, SearchBoxQuerySubmittedEventArgs>>();
		}
开发者ID:Galad,项目名称:Hanno,代码行数:7,代码来源:SearchBoxProperties.cs


示例2: Clear

 /// <inheritdoc/>
 public void Clear()
 {
     lock (objectGuids)
     {
         objectGuids = new ConditionalWeakTable<object, object>();
     }
 }
开发者ID:FERRERDEV,项目名称:xenko,代码行数:8,代码来源:GuidContainer.cs


示例3: GetIndexAsync

        private static async Task<SyntaxTreeIndex> GetIndexAsync(
            Document document,
            ConditionalWeakTable<Document, SyntaxTreeIndex> cache,
            Func<Document, CancellationToken, Task<SyntaxTreeIndex>> generator,
            CancellationToken cancellationToken)
        {
            if (cache.TryGetValue(document, out var info))
            {
                return info;
            }

            info = await generator(document, cancellationToken).ConfigureAwait(false);
            if (info != null)
            {
                return cache.GetValue(document, _ => info);
            }

            // alright, we don't have cached information, re-calculate them here.
            var data = await CreateInfoAsync(document, cancellationToken).ConfigureAwait(false);

            // okay, persist this info
            await data.SaveAsync(document, cancellationToken).ConfigureAwait(false);

            return cache.GetValue(document, _ => data);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:25,代码来源:SyntaxTreeIndex.cs


示例4: WeakKey

        private static void WeakKey()
        {
            var people = new[]
            {
                new Person {Id = 1, Name = "Jurian Naul" },
                new Person {Id = 2, Name = "Thomas Bent" },
                new Person {Id = 3, Name = "Ellen Carson" },
                new Person {Id = 4, Name = "Katrina Lauran" },
                new Person {Id = 5, Name = "Monica Ausbach" },
            };

            var locations = new ConditionalWeakTable<Person, string>();

            locations.Add(people[0], "Shinon");
            locations.Add(people[1], "Lance");
            locations.Add(people[2], "Pidona");
            locations.Add(people[3], "Loanne");
            locations.Add(people[4], "Loanne");

            foreach (var p in people)
            {
                string location;
                if (locations.TryGetValue(p, out location))
                    Console.WriteLine(p.Name + " at " + location);
            }
        }
开发者ID:ufcpp,项目名称:UfcppSample,代码行数:26,代码来源:Program.cs


示例5: AddMany_ThenRemoveAll

        public static void AddMany_ThenRemoveAll(int numObjects)
        {
            object[] keys = Enumerable.Range(0, numObjects).Select(_ => new object()).ToArray();
            object[] values = Enumerable.Range(0, numObjects).Select(_ => new object()).ToArray();
            var cwt = new ConditionalWeakTable<object, object>();

            for (int i = 0; i < numObjects; i++)
            {
                cwt.Add(keys[i], values[i]);
            }

            for (int i = 0; i < numObjects; i++)
            {
                Assert.Same(values[i], cwt.GetValue(keys[i], _ => new object()));
            }

            for (int i = 0; i < numObjects; i++)
            {
                Assert.True(cwt.Remove(keys[i]));
                Assert.False(cwt.Remove(keys[i]));
            }

            for (int i = 0; i < numObjects; i++)
            {
                object ignored;
                Assert.False(cwt.TryGetValue(keys[i], out ignored));
            }
        }
开发者ID:saurabh500,项目名称:corefx,代码行数:28,代码来源:ConditionalWeakTableTests.cs


示例6: Should_release_value_when_there_are_no_more_references

        public void Should_release_value_when_there_are_no_more_references()
        {
            var table = new ConditionalWeakTable<TypeWithStrongReferenceThroughTable, TypeWithWeakReference>();

            var strong = new TypeWithStrongReferenceThroughTable();
            var weak = new TypeWithWeakReference()
                {
                    WeakReference = new WeakReference(strong)
                };

            table.Add(strong, weak);

            GC.Collect();

            TypeWithWeakReference result = null;
            Assert.That(table.TryGetValue(strong, out result), Is.True);
            Assert.That(result, Is.SameAs(weak));

            var weakHandleToStrong = new WeakReference(strong);

            strong = null;

            GC.Collect();

            Assert.That(weakHandleToStrong.IsAlive, Is.False);
        }
开发者ID:bverburg,项目名称:FakeItEasy,代码行数:26,代码来源:ConditionalWeakTableTests.cs


示例7: SaveAsync

        protected async Task<bool> SaveAsync(
            Document document,
            ConditionalWeakTable<BranchId, ConditionalWeakTable<DocumentId, AbstractSyntaxTreeInfo>> cache,
            string persistenceName,
            string serializationFormat,
            CancellationToken cancellationToken)
        {
            var workspace = document.Project.Solution.Workspace;
            var infoTable = GetInfoTable(document.Project.Solution.BranchId, workspace, cache);

            // if it is forked document
            if (await document.IsForkedDocumentWithSyntaxChangesAsync(cancellationToken).ConfigureAwait(false))
            {
                infoTable.Remove(document.Id);
                infoTable.GetValue(document.Id, _ => this);
                return false;
            }

            // okay, cache this info if it is from opened document or persistence failed.
            var persisted = await SaveAsync(document, persistenceName, serializationFormat, this, cancellationToken).ConfigureAwait(false);
            if (!persisted || document.IsOpen())
            {
                var primaryInfoTable = GetInfoTable(workspace.PrimaryBranchId, workspace, cache);
                primaryInfoTable.Remove(document.Id);
                primaryInfoTable.GetValue(document.Id, _ => this);
            }

            return persisted;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:AbstractSyntaxTreeInfo.cs


示例8: GetSyntaxTree

        public Task<XmlNodeSyntax> GetSyntaxTree(ITextSnapshot textSnapshot)
        {
            var textBuffer = textSnapshot.TextBuffer;

            lock (textBuffer)
            {
                ConditionalWeakTable<ITextSnapshot, Task<XmlNodeSyntax>> textSnapshotToSyntaxRootMap;
                Task<XmlNodeSyntax> syntaxRootTask;

                if (!textBuffer.Properties.TryGetProperty(typeof(ParserService), out textSnapshotToSyntaxRootMap))
                {
                    textSnapshotToSyntaxRootMap = new ConditionalWeakTable<ITextSnapshot, Task<XmlNodeSyntax>>();
                    textBuffer.Properties.AddProperty(typeof(ParserService), textSnapshotToSyntaxRootMap);
                }
                else if (textSnapshotToSyntaxRootMap.TryGetValue(textSnapshot, out syntaxRootTask))
                {
                    return syntaxRootTask;
                }

                syntaxRootTask = Task.Run(() => Parse(textSnapshot));
                textSnapshotToSyntaxRootMap.Add(textSnapshot, syntaxRootTask);

                return syntaxRootTask;
            }
        }
开发者ID:akrisiun,项目名称:Microsoft.Language.Xml,代码行数:25,代码来源:ParserService.cs


示例9: GetValue

        public void GetValue()
        {
            var cwt = new ConditionalWeakTable<object, object>();

            try
            {
                cwt.GetValue(null, k => null);
                Assert.Fail("#0");
            }
            catch (ArgumentNullException) { }

            try
            {
                cwt.GetValue(20, null);
                Assert.Fail("#1");
            }
            catch (ArgumentNullException) { }


            object key = "foo";
            object val = cwt.GetValue(key, k => new Link(k));
            Assert.IsTrue(val != null, "#2");
            Assert.AreEqual(typeof(Link), val.GetType(), "#3");

            Assert.AreEqual(val, cwt.GetValue(key, k => new object()), "#4");
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:26,代码来源:ConditionalWeakTableTest.cs


示例10: OnNewAnalyzer

        internal void OnNewAnalyzer(PythonAnalyzer analyzer) {
            if (analyzer == null) {
                throw new ArgumentNullException("analyzer");
            }

            _tags.Clear();
            _filters.Clear();
            foreach (var entry in _hookedEntries) {
                entry.OnNewParseTree -= OnNewParseTree;
            }
            _hookedEntries.Clear();
            _templateAnalysis.Clear();
            _templateFiles.Clear();
            _contextTable = new ConditionalWeakTable<Node, ContextMarker>();
            _decoratorTable = new ConditionalWeakTable<Node, DeferredDecorator>();

            foreach (var keyValue in _knownTags) {
                _tags[keyValue.Key] = new TagInfo(keyValue.Value, null);
            }
            foreach (var keyValue in _knownFilters) {
                _filters[keyValue.Key] = new TagInfo(keyValue.Value, null);
            }

            HookAnalysis(analyzer);
            _analyzer = analyzer;
        }
开发者ID:rajpaswan,项目名称:PTVS,代码行数:26,代码来源:DjangoAnalyzer.cs


示例11: ObservableCommand

 /// <summary>
 /// Executes an action.
 /// </summary>
 public ObservableCommand(Func<object, bool> canExecuteFunc = null, bool enabled = true)
 {
     this.enabled = enabled;
     this.canExecuteFunc = canExecuteFunc;
     this.proxies = new List<WeakReference<ObservableCommandProxy>>();
     this.proxyHandlers = new ConditionalWeakTable<ObservableCommandProxy, EventHandler>();
 }
开发者ID:jp7837,项目名称:onebusaway-windows8,代码行数:10,代码来源:ObservableCommand.cs


示例12: QueryFutureManager

        /// <summary>Static constructor.</summary>
        static QueryFutureManager()
        {
#if EF5 || EF6
            CacheWeakFutureBatch = new ConditionalWeakTable<ObjectContext, QueryFutureBatch>();
#elif EFCORE
            CacheWeakFutureBatch = new ConditionalWeakTable<DbContext, QueryFutureBatch>();
#endif
        }
开发者ID:emmatb1,项目名称:EntityFramework-Plus,代码行数:9,代码来源:QueryFutureManager.cs


示例13: AnalyzerManager

        public AnalyzerManager(ImmutableArray<AnalyzerReference> hostAnalyzerReferences)
        {
            _hostAnalyzerReferencesMap = hostAnalyzerReferences.IsDefault ? ImmutableDictionary<string, AnalyzerReference>.Empty : CreateAnalyzerReferencesMap(hostAnalyzerReferences);
            _hostDiagnosticAnalyzersPerReferenceMap = CreateDiagnosticAnalyzersPerReferenceMap(_hostAnalyzerReferencesMap);

            _hostDiagnosticAnalyzersPerLanguageMap = new ConcurrentDictionary<string, ImmutableDictionary<string, ImmutableArray<DiagnosticAnalyzer>>>(concurrencyLevel: 2, capacity: 2);
            _descriptorCache = new ConditionalWeakTable<DiagnosticAnalyzer, IReadOnlyList<DiagnosticDescriptor>>();

            DiagnosticAnalyzerLogger.LogWorkspaceAnalyzers(hostAnalyzerReferences);
        }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:10,代码来源:AnalyzerManager.cs


示例14: AnalysisState

 public AnalysisState(ImmutableArray<DiagnosticAnalyzer> analyzers)
 {
     _gate = new object();
     _analyzerStateMap = CreateAnalyzerStateMap(analyzers);
     _pendingSourceEvents = new Dictionary<SyntaxTree, HashSet<CompilationEvent>>();
     _pendingNonSourceEvents = new HashSet<CompilationEvent>();
     _lazyAnalyzerActionCountsMap = null;
     _semanticModelsMap = new ConditionalWeakTable<SyntaxTree, SemanticModel>();
     _compilationEventsPool = new ObjectPool<HashSet<CompilationEvent>>(() => new HashSet<CompilationEvent>());
 }
开发者ID:Excoriate,项目名称:roslyn,代码行数:10,代码来源:AnalysisState.cs


示例15: TryGetInitialVersions

        private bool TryGetInitialVersions(ConditionalWeakTable<ProjectId, Versions> initialVersionMap, Project project, string keyName, out Versions versions)
        {
            // if we already loaded this, return it.
            if (initialVersionMap.TryGetValue(project.Id, out versions))
            {
                return true;
            }

            // otherwise, load it
            return TryLoadInitialVersions(initialVersionMap, project, keyName, out versions);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:11,代码来源:SemanticVersionTrackingService.cs


示例16: AnalysisState

 public AnalysisState(ImmutableArray<DiagnosticAnalyzer> analyzers)
 {
     _gate = new SemaphoreSlim(initialCount: 1);
     _analyzerStateMap = CreateAnalyzerStateMap(analyzers, out _analyzerStates);
     _pendingSourceEvents = new Dictionary<SyntaxTree, HashSet<CompilationEvent>>();
     _pendingNonSourceEvents = new HashSet<CompilationEvent>();
     _lazyAnalyzerActionCountsMap = null;
     _semanticModelsMap = new ConditionalWeakTable<SyntaxTree, SemanticModel>();
     _compilationEventsPool = new ObjectPool<HashSet<CompilationEvent>>(() => new HashSet<CompilationEvent>());
     _pooledEventsWithAnyActionsSet = new HashSet<CompilationEvent>();
     _compilationEndAnalyzed = false;
 }
开发者ID:ralfkang,项目名称:roslyn,代码行数:12,代码来源:AnalysisState.cs


示例17: InitializeEnableXamlSourceInfo

 private static void InitializeEnableXamlSourceInfo(string value)
 {
     // Initialize source info support. Source info is disabled if value
     // is empty, 0 or false (case insensitive). Otherwise true.
     value = (value ?? string.Empty).Trim().ToLowerInvariant();
     if (value == string.Empty || value == "0" || value == "false" || !InitializeXamlObjectEventArgs())
     {
         s_sourceInfoTable = null;
     }
     else
     {
         s_sourceInfoTable = new ConditionalWeakTable<object, XamlSourceInfo>();
     }
 }
开发者ID:mind0n,项目名称:hive,代码行数:14,代码来源:XamlSourceInfoHelper.cs


示例18: InvalidArgs_Throws

        public static void InvalidArgs_Throws()
        {
            var cwt = new ConditionalWeakTable<object, object>();

            object ignored;
            Assert.Throws<ArgumentNullException>("key", () => cwt.Add(null, new object())); // null key
            Assert.Throws<ArgumentNullException>("key", () => cwt.TryGetValue(null, out ignored)); // null key
            Assert.Throws<ArgumentNullException>("key", () => cwt.Remove(null)); // null key
            Assert.Throws<ArgumentNullException>("createValueCallback", () => cwt.GetValue(new object(), null)); // null delegate

            object key = new object();
            cwt.Add(key, key);
            Assert.Throws<ArgumentException>(null, () => cwt.Add(key, key)); // duplicate key
        }
开发者ID:saurabh500,项目名称:corefx,代码行数:14,代码来源:ConditionalWeakTableTests.cs


示例19: GetOrCreateCompilationActionsCache

        private ConditionalWeakTable<Compilation, Task<HostCompilationStartAnalysisScope>> GetOrCreateCompilationActionsCache(AnalyzerAndOptions analyzerAndOptions)
        {
            lock (_compilationScopeMap)
            {
                ConditionalWeakTable<Compilation, Task<HostCompilationStartAnalysisScope>> value;
                if (_compilationScopeMap.TryGetValue(analyzerAndOptions, out value))
                {
                    return value;
                }

                value = new ConditionalWeakTable<Compilation, Task<HostCompilationStartAnalysisScope>>();
                _compilationScopeMap.Add(analyzerAndOptions, value);
                return value;
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:15,代码来源:AnalyzerManager.cs


示例20: AnalysisState

 public AnalysisState(ImmutableArray<DiagnosticAnalyzer> analyzers, CompilationData compilationData)
 {
     _gate = new object();
     _analyzerStateMap = CreateAnalyzerStateMap(analyzers, out _analyzerStates);
     _compilationData = compilationData;
     _pendingSourceEvents = new Dictionary<SyntaxTree, HashSet<CompilationEvent>>();
     _pendingNonSourceEvents = new HashSet<CompilationEvent>();
     _lazyAnalyzerActionCountsMap = null;
     _semanticModelsMap = new ConditionalWeakTable<SyntaxTree, SemanticModel>();
     _treesWithGeneratedSourceEvents = new HashSet<SyntaxTree>();
     _partialSymbolsWithGeneratedSourceEvents = new HashSet<ISymbol>();
     _compilationStartGenerated = false;
     _compilationEndGenerated = false;
     _compilationEventsPool = new ObjectPool<HashSet<CompilationEvent>>(() => new HashSet<CompilationEvent>());
     _pooledEventsWithAnyActionsSet = new HashSet<CompilationEvent>();
 }
开发者ID:bgarate,项目名称:roslyn,代码行数:16,代码来源:AnalysisState.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Conditions类代码示例发布时间:2022-05-24
下一篇:
C# ConditionalExpression类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap