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


C# Cache.ContainsKey方法代码示例

本文整理汇总了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);
        }
开发者ID:RyanHauert,项目名称:presentations-immutability,代码行数:8,代码来源:CacheTests.cs

示例2: CanAdd

        public void CanAdd()
        {
            var cache = new Cache<string, string>();
            cache["Foo"] = "Bar";

            cache.ContainsKey("Foo").ShouldBe(true);
            cache["Foo"].ShouldBe("Bar");
        }
开发者ID:RyanHauert,项目名称:presentations-immutability,代码行数:8,代码来源:CacheTests.cs

示例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;
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:34,代码来源:TechTree.cs

示例4: IsHidden

 bool IsHidden(Cache<string, List<Actor>> ownedPrerequisites)
 {
     return prerequisites.Any(prereq => prereq.StartsWith("~") &&
         (prereq.Replace("~", "").StartsWith("!") ^ !ownedPrerequisites.ContainsKey(prereq.Replace("~", "").Replace("!", ""))));
 }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:5,代码来源:TechTree.cs

示例5: HasPrerequisites

 bool HasPrerequisites(Cache<string, List<Actor>> ownedPrerequisites)
 {
     return prerequisites.All(p => !(p.Replace("~", "").StartsWith("!") ^ !ownedPrerequisites.ContainsKey(p.Replace("!", "").Replace("~", ""))));
 }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:4,代码来源:TechTree.cs

示例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;
            }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:31,代码来源:TechTree.cs

示例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);
         }
     }
 }
开发者ID:WeTeam,项目名称:WeBlog,代码行数:19,代码来源:TranslatorCache.cs

示例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);
                }
            }
        }
开发者ID:KerwinMa,项目名称:WeBlog,代码行数:25,代码来源:Translator.cs


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