本文整理汇总了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>>();
}
示例2: Clear
/// <inheritdoc/>
public void Clear()
{
lock (objectGuids)
{
objectGuids = new ConditionalWeakTable<object, object>();
}
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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");
}
示例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;
}
示例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>();
}
示例12: QueryFutureManager
/// <summary>Static constructor.</summary>
static QueryFutureManager()
{
#if EF5 || EF6
CacheWeakFutureBatch = new ConditionalWeakTable<ObjectContext, QueryFutureBatch>();
#elif EFCORE
CacheWeakFutureBatch = new ConditionalWeakTable<DbContext, QueryFutureBatch>();
#endif
}
示例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);
}
示例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>());
}
示例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);
}