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


C# IConfiguration.ContainsKey方法代码示例

本文整理汇总了C#中IConfiguration.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# IConfiguration.ContainsKey方法的具体用法?C# IConfiguration.ContainsKey怎么用?C# IConfiguration.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConfiguration的用法示例。


在下文中一共展示了IConfiguration.ContainsKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SiteContextGenerator

        public SiteContextGenerator(IFileSystem fileSystem, LinkHelper linkHelper, IConfiguration config)
        {
            this.fileSystem = fileSystem;
            this.linkHelper = linkHelper;
            _config = config;

            if (_config.ContainsKey("include"))
            {
                includes.AddRange((IEnumerable<string>)_config["include"]);
            }
            if (_config.ContainsKey("exclude"))
            {
                excludes.AddRange((IEnumerable<string>)_config["exclude"]);
            }
        }
开发者ID:Code52,项目名称:pretzel,代码行数:15,代码来源:SiteContextGenerator.cs

示例2: AddOrChangeProperty

 /// <summary>
 /// Add or update the property in the underlying config depending on if it exists
 /// </summary>
 /// <param name="name"></param>
 /// <param name="newValue"></param>
 /// <param name="config"></param>
 public void AddOrChangeProperty(string name, object newValue, IConfiguration config)
 {
     // We do not want to abort the operation due to failed validation on one property
     try
     {
         if (!config.ContainsKey(name))
         {
             m_Log.DebugFormat("Adding property key [{0}], value [{1}]", name, newValue);
             config.AddProperty(name, newValue);
             return;
         }
         var oldValue = config.GetProperty(name);
         if (newValue != null)
         {
             object newValueArray;
             if (oldValue is IList && config.ListDelimiter != '\0')
             {
                 newValueArray = new ArrayList();
                 var values = ((string)newValue).Split(config.ListDelimiter).Select(v => v.Trim()).Where(v => v.Length != 0);
                 foreach (var value in values)
                 {
                     ((IList)newValueArray).Add(value);
                 }
             }
             else
             {
                 newValueArray = newValue;
             }
             if (!ObjectUtils.AreEqual(newValueArray, oldValue))
             {
                 m_Log.DebugFormat("Updating property key [{0}], value [{1}]", name, newValue);
                 config.SetProperty(name, newValue);
             }
         }
         else if (oldValue != null)
         {
             m_Log.DebugFormat("nulling out property key [{0}]", name);
             config.SetProperty(name, null);
         }
     }
     catch (ValidationException e)
     {
         m_Log.Warn("Validation failed for property " + name, e);
     }
 }
开发者ID:CH3CHO,项目名称:Archaius.Net,代码行数:51,代码来源:DynamicPropertyUpdater.cs

示例3: DeleteProperty

 /// <summary>
 /// Delete a property in the underlying config
 /// </summary>
 /// <param name="key"></param>
 /// <param name="config"></param>
 public void DeleteProperty(string key, IConfiguration config)
 {
     if (!config.ContainsKey(key))
     {
         return;
     }
     m_Log.DebugFormat("Deleting property key [{0}]", key);
     config.ClearProperty(key);
 }
开发者ID:CH3CHO,项目名称:Archaius.Net,代码行数:14,代码来源:DynamicPropertyUpdater.cs

示例4: CreatePage

        private Page CreatePage(SiteContext context, IConfiguration config, string file, bool isPost)
        {
            try
            {
                if (pageCache.ContainsKey(file))
                    return pageCache[file];
                var content = SafeReadContents(file);

                var relativePath = MapToOutputPath(context, file);
                var scopedDefaults = context.Config.Defaults.ForScope(relativePath);

                var header = scopedDefaults.Merge(content.YamlHeader());

                if (header.ContainsKey("published") && header["published"].ToString().ToLower() == "false")
                {
                    return null;
                }

                var page = new Page
                                {
                                    Title = header.ContainsKey("title") ? header["title"].ToString() : "this is a post",
                                    Date = header.ContainsKey("date") ? DateTime.Parse(header["date"].ToString()) : file.Datestamp(fileSystem),
                                    Content = content,
                                    Filepath = isPost ? GetPathWithTimestamp(context.OutputFolder, file) : GetFilePathForPage(context, file),
                                    File = file,
                                    Bag = header,
                                };

                // resolve categories and tags
                if (isPost)
                {
                    page.Categories = ResolveCategories(context, header, page);

                    if (header.ContainsKey("tags"))
                        page.Tags = header["tags"] as IEnumerable<string>;
                }

                // resolve permalink
                if (header.ContainsKey("permalink"))
                {
                    page.Url = linkHelper.EvaluatePermalink(header["permalink"].ToString(), page);
                }
                else if (isPost && config.ContainsKey("permalink"))
                {
                    page.Url = linkHelper.EvaluatePermalink(config["permalink"].ToString(), page);
                }
                else
                {
                    page.Url = linkHelper.EvaluateLink(context, page);
                }

                // resolve id
                page.Id = page.Url.Replace(".html", string.Empty).Replace("index", string.Empty);

                // always write date back to Bag as DateTime
                page.Bag["date"] = page.Date;

                // The GetDirectoryPage method is reentrant, we need a cache to stop a stack overflow :)
                pageCache.Add(file, page);
                page.DirectoryPages = GetDirectoryPages(context, config, Path.GetDirectoryName(file), isPost).ToList();

                return page;
            }
            catch (Exception e)
            {
                Tracing.Info(String.Format("Failed to build post from File: {0}", file));
                Tracing.Info(e.Message);
                Tracing.Debug(e.ToString());
            }

            return null;
        }
开发者ID:Code52,项目名称:pretzel,代码行数:72,代码来源:SiteContextGenerator.cs


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