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


C# ConditionalWeakTable类代码示例

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


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


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