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


C# IDictionary.GetOrAdd方法代码示例

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


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

示例1: CreateTestFile

        public static string CreateTestFile(string code, IDictionary<string, IList<TextSpan>> spans, int cursor = -1)
        {
            var sb = new StringBuilder();
            var anonymousSpans = spans.GetOrAdd(string.Empty, () => new List<TextSpan>());

            for (int i = 0; i <= code.Length; i++)
            {
                if (i == cursor)
                {
                    sb.Append(PositionString);
                }

                AddSpanString(sb, spans.Where(kvp => kvp.Key != string.Empty), i, start: true);
                AddSpanString(sb, spans.Where(kvp => kvp.Key == string.Empty), i, start: true);
                AddSpanString(sb, spans.Where(kvp => kvp.Key == string.Empty), i, start: false);
                AddSpanString(sb, spans.Where(kvp => kvp.Key != string.Empty), i, start: false);

                if (i < code.Length)
                {
                    sb.Append(code[i]);
                }
            }

            return sb.ToString();
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:25,代码来源:MarkupTestFile.cs

示例2: PopSpan

        private static void PopSpan(
            Stack<Tuple<int, string>> spanStartStack,
            IDictionary<string, IList<TextSpan>> spans,
            int finalIndex)
        {
            var spanStartTuple = spanStartStack.Pop();

            var span = TextSpan.FromBounds(spanStartTuple.Item1, finalIndex);
            spans.GetOrAdd(spanStartTuple.Item2, () => new List<TextSpan>()).Add(span);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:10,代码来源:MarkupTestFile.cs

示例3: HandleBodyLinks

        /// <summary>
        /// Handles links embedded in JSON response bodies.
        /// </summary>
        /// <param name="jsonBody">The body to check for links.</param>
        /// <param name="links">A dictionary to add found links to.</param>
        /// <param name="linkTemplates">A dictionary to add found link templates to.</param>
        protected virtual void HandleBodyLinks(JToken jsonBody, IDictionary<string, Dictionary<Uri, string>> links, IDictionary<string, UriTemplate> linkTemplates)
        {
            if (jsonBody.Type != JTokenType.Object) return;
            var linksNode = jsonBody["_links"] ?? jsonBody["links"];
            if (linksNode == null) return;

            foreach (var linkNode in linksNode.OfType<JProperty>())
            {
                string rel = linkNode.Name;
                var linksForRel = links.GetOrAdd(rel);

                switch (linkNode.Value.Type)
                {
                    case JTokenType.Array:
                        foreach (var subobj in linkNode.Value.OfType<JObject>())
                            ParseLinkObject(rel, subobj, linksForRel, linkTemplates);
                        break;

                    case JTokenType.Object:
                        ParseLinkObject(rel, (JObject)linkNode.Value, linksForRel, linkTemplates);
                        break;
                }
            }
        }
开发者ID:1and1,项目名称:TypedRest-DotNet,代码行数:30,代码来源:EndpointBase.cs

示例4: CommandAttribute

 public CommandAttribute(IDictionary<string, object> attributes)
     : this((string)attributes.GetOrAdd("PackageId", _ => Guid.Empty.ToString()), (string)attributes["GroupId"], (int)attributes["CommandId"])
 {
 }
开发者ID:MobileEssentials,项目名称:clide,代码行数:4,代码来源:CommandAttribute.cs

示例5: HandleHeaderLinks

 /// <summary>
 /// Handles links embedded in HTTP response headers.
 /// </summary>
 /// <param name="headers">The headers to check for links.</param>
 /// <param name="links">A dictionary to add found links to.</param>
 /// <param name="linkTemplates">A dictionary to add found link templates to.</param>
 protected virtual void HandleHeaderLinks(HttpResponseHeaders headers, IDictionary<string, Dictionary<Uri, string>> links, IDictionary<string, UriTemplate> linkTemplates)
 {
     foreach (var header in headers.GetLinkHeaders().Where(x => x.Rel != null))
     {
         if (header.Templated)
             linkTemplates[header.Rel] = new UriTemplate(header.Href);
         else
             links.GetOrAdd(header.Rel)[new Uri(Uri, header.Href)] = header.Title;
     }
 }
开发者ID:1and1,项目名称:TypedRest-DotNet,代码行数:16,代码来源:EndpointBase.cs


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