forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapExtensions.cs
More file actions
40 lines (36 loc) · 1.14 KB
/
MapExtensions.cs
File metadata and controls
40 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// https://github.com/ServiceStack/ServiceStack.Text
// ServiceStack.Text: .NET C# POCO JSON, JSV and CSV Text Serializers.
//
// Authors:
// Demis Bellot (demis.bellot@gmail.com)
//
// Copyright 2012 ServiceStack, Inc. All Rights Reserved.
//
// Licensed under the same terms of ServiceStack.
//
using System.Collections.Generic;
using System.Text;
using ServiceStack.Text;
using ServiceStack.Text.Common;
namespace ServiceStack
{
public static class MapExtensions
{
public static string Join<K, V>(this Dictionary<K, V> values)
{
return Join(values, JsWriter.ItemSeperatorString, JsWriter.MapKeySeperatorString);
}
public static string Join<K, V>(this Dictionary<K, V> values, string itemSeperator, string keySeperator)
{
var sb = StringBuilderThreadStatic.Allocate();
foreach (var entry in values)
{
if (sb.Length > 0)
sb.Append(itemSeperator);
sb.Append(entry.Key).Append(keySeperator).Append(entry.Value);
}
return StringBuilderThreadStatic.ReturnAndFree(sb);
}
}
}