本文整理汇总了C#中Cache.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.ContainsKey方法的具体用法?C# Cache.ContainsKey怎么用?C# Cache.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache.ContainsKey方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanRemove
public void CanRemove()
{
var cache = new Cache<string, string>();
cache["Foo"] = "Bar";
cache.Remove("Foo").ShouldBe(true);
cache.ContainsKey("Foo").ShouldBe(false);
}
示例2: CanAdd
public void CanAdd()
{
var cache = new Cache<string, string>();
cache["Foo"] = "Bar";
cache.ContainsKey("Foo").ShouldBe(true);
cache["Foo"].ShouldBe("Bar");
}
示例3: GatherOwnedPrerequisites
static Cache<string, List<Actor>> GatherOwnedPrerequisites(Player player)
{
var ret = new Cache<string, List<Actor>>(x => new List<Actor>());
if (player == null)
return ret;
// Add all actors that provide prerequisites
var prerequisites = player.World.ActorsWithTrait<ITechTreePrerequisite>()
.Where(a => a.Actor.Owner == player && a.Actor.IsInWorld && !a.Actor.IsDead);
foreach (var b in prerequisites)
{
foreach (var p in b.Trait.ProvidesPrerequisites)
{
// Ignore bogus prerequisites
if (p == null)
continue;
ret[p].Add(b.Actor);
}
}
// Add buildables that have a build limit set and are not already in the list
player.World.ActorsWithTrait<Buildable>()
.Where(a =>
a.Actor.Owner == player &&
a.Actor.IsInWorld &&
!a.Actor.IsDead &&
!ret.ContainsKey(a.Actor.Info.Name) &&
a.Actor.Info.TraitInfo<BuildableInfo>().BuildLimit > 0)
.Do(b => ret[b.Actor.Info.Name].Add(b.Actor));
return ret;
}
示例4: IsHidden
bool IsHidden(Cache<string, List<Actor>> ownedPrerequisites)
{
return prerequisites.Any(prereq => prereq.StartsWith("~") &&
(prereq.Replace("~", "").StartsWith("!") ^ !ownedPrerequisites.ContainsKey(prereq.Replace("~", "").Replace("!", ""))));
}
示例5: HasPrerequisites
bool HasPrerequisites(Cache<string, List<Actor>> ownedPrerequisites)
{
return prerequisites.All(p => !(p.Replace("~", "").StartsWith("!") ^ !ownedPrerequisites.ContainsKey(p.Replace("!", "").Replace("~", ""))));
}
示例6: Update
public void Update(Cache<string, List<Actor>> ownedPrerequisites)
{
var hasReachedLimit = limit > 0 && ownedPrerequisites.ContainsKey(Key) && ownedPrerequisites[Key].Count >= limit;
// The '!' annotation inverts prerequisites: "I'm buildable if this prerequisite *isn't* met"
var nowHasPrerequisites = HasPrerequisites(ownedPrerequisites) && !hasReachedLimit;
var nowHidden = IsHidden(ownedPrerequisites);
if (initialized == false)
{
initialized = true;
hasPrerequisites = !nowHasPrerequisites;
hidden = !nowHidden;
}
// Hide the item from the UI if a prereq annotated with '~' is not met.
if (nowHidden && !hidden)
watcher.PrerequisitesItemHidden(Key);
if (!nowHidden && hidden)
watcher.PrerequisitesItemVisible(Key);
if (nowHasPrerequisites && !hasPrerequisites)
watcher.PrerequisitesAvailable(Key);
if (!nowHasPrerequisites && hasPrerequisites)
watcher.PrerequisitesUnavailable(Key);
hidden = nowHidden;
hasPrerequisites = nowHasPrerequisites;
}
示例7: PopulateCache
/// <summary>
/// Populates the cache.
/// </summary>
/// <param name="cache">The cache.</param>
protected void PopulateCache(Cache cache)
{
Item dictionaryItem = ManagerFactory.BlogManagerInstance.GetDictionaryItem();
_cacheRootId = dictionaryItem.ID;
IEnumerable<Item> entries = dictionaryItem.Axes.GetDescendants();
entries = entries.Where(entry => entry.TemplateID == Settings.DictionaryEntryTemplateID);
foreach (Item entry in entries)
{
string key = entry[Key].Trim();
if (!cache.ContainsKey(key))
{
cache.Add(key, entry.ID);
}
}
}
示例8: PopulateCache
/// <summary>
/// Populates the cache.
/// </summary>
/// <param name="cache">The cache.</param>
protected static void PopulateCache(Cache cache)
{
Item dictionaryItem = ManagerFactory.BlogManagerInstance.GetDictionaryItem();
_cacheRootID = dictionaryItem.ID;
if (dictionaryItem == null)
{
Log.Error("No dictionary configured for blog " + ManagerFactory.BlogManagerInstance.GetCurrentBlog().SafeGet(x => x.Name), typeof(Translator));
return;
}
IEnumerable<Item> entries = dictionaryItem.Axes.GetDescendants();
entries = entries.Where(entry => entry.TemplateID == Settings.DictionaryEntryTemplateID);
foreach (Item entry in entries)
{
string key = entry[KEY].Trim();
if (!cache.ContainsKey(key))
{
cache.Add(key, entry.ID);
}
}
}