本文整理汇总了C#中Dictionary.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ToArray方法的具体用法?C# Dictionary.ToArray怎么用?C# Dictionary.ToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTokenByPinRequest
/// <exception cref="ArgumentNullException">
/// Thrown when a null reference is passed to a method that does not accept it as a
/// valid argument.
/// </exception>
internal HttpRequestMessage GetTokenByPinRequest(string url, string pin, string clientId, string clientSecret)
{
if (string.IsNullOrWhiteSpace(url))
throw new ArgumentNullException(nameof(url));
if (string.IsNullOrWhiteSpace(pin))
throw new ArgumentNullException(nameof(pin));
if (string.IsNullOrWhiteSpace(clientId))
throw new ArgumentNullException(nameof(clientId));
if (string.IsNullOrWhiteSpace(clientSecret))
throw new ArgumentNullException(nameof(clientSecret));
var parameters = new Dictionary<string, string>
{
{"client_id", clientId},
{"client_secret", clientSecret},
{"grant_type", "pin"},
{"pin", pin}
};
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例2: CreateCommentRequest
/// <exception cref="ArgumentNullException"></exception>
internal HttpRequestMessage CreateCommentRequest(string url, string comment, string imageId, string parentId)
{
if (string.IsNullOrEmpty(url))
throw new ArgumentNullException(nameof(url));
if (string.IsNullOrEmpty(comment))
throw new ArgumentNullException(nameof(comment));
if (string.IsNullOrEmpty(imageId))
throw new ArgumentNullException(nameof(imageId));
var parameters = new Dictionary<string, string>
{
{"image_id", imageId},
{"comment", comment}
};
if (!string.IsNullOrWhiteSpace(parentId))
parameters.Add("parent_id", parentId);
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例3: PublishToGalleryRequest
/// <exception cref="ArgumentNullException">
/// Thrown when a null reference is passed to a method that does not accept it as a
/// valid argument.
/// </exception>
internal HttpRequestMessage PublishToGalleryRequest(string url, string title,
string topicId = null, bool? bypassTerms = null, bool? mature = null)
{
if (string.IsNullOrWhiteSpace(url))
throw new ArgumentNullException(nameof(url));
if (string.IsNullOrWhiteSpace(title))
throw new ArgumentNullException(nameof(title));
var parameters = new Dictionary<string, string> {{nameof(title), title}};
if (topicId != null)
parameters.Add("topic", topicId);
if (bypassTerms != null)
parameters.Add("terms", $"{bypassTerms}".ToLower());
if (mature != null)
parameters.Add(nameof(mature), $"{mature}".ToLower());
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例4: GetGems
static int GetGems(string[] stones)
{
var elements = new Dictionary<char, bool>();
for (var j = 0; j < stones[0].Length; j++)
{
var c = stones[0][j];
if (!elements.ContainsKey(stones[0][j]))
{
elements.Add(c, true);
}
}
for (var i = 1; i < stones.Length; i++)
{
var arr = elements.ToArray();
for (var j = 0; j < arr.Length; j++)
{
var c = arr[j].Key;
if (stones[i].IndexOf(c) == -1)
{
elements.Remove(c);
}
}
}
return elements.Keys.Count();
}
示例5: PublishRequest
internal HttpRequestMessage PublishRequest(string url, string title, string topic, bool? acceptTerms, bool? nsfw)
{
if (string.IsNullOrEmpty(url))
throw new ArgumentNullException(nameof(url));
if (string.IsNullOrEmpty(title))
throw new ArgumentNullException(nameof(title));
var parameters = new Dictionary<string, string>()
{
{ "title", title }
};
if (!string.IsNullOrEmpty(topic))
parameters.Add("topic", topic);
if (acceptTerms != null)
parameters.Add("terms", (bool)acceptTerms ? "1" : "0");
if (nsfw != null)
parameters.Add("mature", (bool)nsfw ? "1" : "0");
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例6: CreateAlbumRequest
/// <exception cref="ArgumentNullException">
/// Thrown when a null reference is passed to a method that does not accept it as a
/// valid argument.
/// </exception>
internal HttpRequestMessage CreateAlbumRequest(string url,
string title = null, string description = null,
AlbumPrivacy? privacy = null, AlbumLayout? layout = null,
string coverId = null, IEnumerable<string> imageIds = null)
{
if (string.IsNullOrWhiteSpace(url))
throw new ArgumentNullException(nameof(url));
var parameters = new Dictionary<string, string>();
if (privacy != null)
parameters.Add(nameof(privacy), $"{privacy}".ToLower());
if (layout != null)
parameters.Add(nameof(layout), $"{layout}".ToLower());
if (coverId != null)
parameters.Add("cover", coverId);
if (title != null)
parameters.Add(nameof(title), title);
if (description != null)
parameters.Add(nameof(description), description);
if (imageIds != null)
parameters.Add("ids", string.Join(",", imageIds));
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例7: ParseScript
public static Script ParseScript(string s)
{
MemoryStream result = new MemoryStream();
if(mapOpNames.Count == 0)
{
mapOpNames = new Dictionary<string, OpcodeType>(Op._OpcodeByName);
foreach(var kv in mapOpNames.ToArray())
{
if(kv.Key.StartsWith("OP_", StringComparison.Ordinal))
{
var name = kv.Key.Substring(3, kv.Key.Length - 3);
mapOpNames.AddOrReplace(name, kv.Value);
}
}
}
var words = s.Split(' ', '\t', '\n');
foreach(string w in words)
{
if(w == "")
continue;
if(w.All(l => l.IsDigit()) ||
(w.StartsWith("-") && w.Substring(1).All(l => l.IsDigit())))
{
// Number
long n = long.Parse(w);
Op.GetPushOp(new BigInteger(n)).WriteTo(result);
}
else if(w.StartsWith("0x") && HexEncoder.IsWellFormed(w.Substring(2)))
{
// Raw hex data, inserted NOT pushed onto stack:
var raw = Encoders.Hex.DecodeData(w.Substring(2));
result.Write(raw, 0, raw.Length);
}
else if(w.Length >= 2 && w.StartsWith("'") && w.EndsWith("'"))
{
// Single-quoted string, pushed as data. NOTE: this is poor-man's
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
var b = TestUtils.ToBytes(w.Substring(1, w.Length - 2));
Op.GetPushOp(b).WriteTo(result);
}
else if(mapOpNames.ContainsKey(w))
{
// opcode, e.g. OP_ADD or ADD:
result.WriteByte((byte)mapOpNames[w]);
}
else
{
Assert.True(false, "Invalid test");
return null;
}
}
return new Script(result.ToArray());
}
示例8: RecognizedGesture
public RecognizedGesture(Dictionary<string, SimpleGesture[]> gestures)
{
if (gestures == null || gestures.Count < 1)
throw new ArgumentNullException("gestures");
Gesture = gestures.ToArray();
Machines = (from g in Gesture select new KeyValuePair<string, RecognitionSequenceMachine>(g.Key, new RecognitionSequenceMachine(g.Value))).ToArray();
}
示例9: DictionaryExtensions_Unit_AsReadOnly_Optimal
public void DictionaryExtensions_Unit_AsReadOnly_Optimal()
{
IDictionary<String, DateTime> dictionary = new Dictionary<String, DateTime>() {
{ "One", DateTime.Today.AddDays(-1) },
{ "Two", DateTime.Today },
{ "Three", DateTime.Today.AddDays(1) } };
ReadOnlyDictionary<String, DateTime> actual = DictionaryExtensions.AsReadOnly(dictionary);
CollectionAssert.AreEquivalent(dictionary.ToArray(pair => pair), actual.ToArray(pair => pair));
}
示例10: MainMenuSource
public MainMenuSource (Dictionary<string,Action> buttonDictionary)
{
TableCells = new List<UITableViewCell> ();
ButtonArray = buttonDictionary.ToArray ();
foreach (var buttonProperty in ButtonArray) {
var cell = new UITableViewCell ();
cell.TextLabel.Text = buttonProperty.Key;
TableCells.Add (cell);
}
}
示例11: ReportCommentRequest
internal HttpRequestMessage ReportCommentRequest(string url, ReportReason reason)
{
var parameters = new Dictionary<string, string>
{
{"reason", ((int) reason).ToString()}
};
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例12: Main
static void Main(string[] args)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("contacts[0].Name", "张三");
dictionary.Add("contacts[0].PhoneNo", "123456789");
dictionary.Add("contacts[0].EmailAddress", "[email protected]");
dictionary.Add("contacts[1].Name", "李四");
dictionary.Add("contacts[1].PhoneNo", "987654321");
dictionary.Add("contacts[1].EmailAddress", "[email protected]");
NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(dictionary.ToArray(), null);
//Prefix=""
Console.WriteLine("Prefix: <Empty>");
Console.WriteLine("{0,-14}{1}", "Key", "Value");
IDictionary<string, string> keys = valueProvider.GetKeysFromPrefix(string.Empty);
foreach (var item in keys)
{
Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
}
//Prefix="contact"
Console.WriteLine("\nPrefix: contact");
Console.WriteLine("{0,-14}{1}", "Key", "Value");
keys = valueProvider.GetKeysFromPrefix("contact");
foreach (var item in keys)
{
Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
}
//Prefix="contacts[0]"
Console.WriteLine("\nPrefix: contacts[0]");
Console.WriteLine("{0,-14}{1}", "Key", "Value");
keys = valueProvider.GetKeysFromPrefix("contacts[0]");
foreach (var item in keys)
{
Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
}
//Prefix="contacts[1]"
Console.WriteLine("\nPrefix: contacts[1]");
Console.WriteLine("{0,-14}{1}", "Key", "Value");
keys = valueProvider.GetKeysFromPrefix("contacts[1]");
foreach (var item in keys)
{
Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
}
}
示例13: UpdateAccountSettingsRequest
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
internal HttpRequestMessage UpdateAccountSettingsRequest(
string url,
string bio = null,
bool? publicImages = null,
bool? messagingEnabled = null,
AlbumPrivacy? albumPrivacy = null,
bool? acceptedGalleryTerms = null,
string username = null,
bool? showMature = null,
bool? newsletterSubscribed = null)
{
if (string.IsNullOrEmpty(url))
throw new ArgumentNullException(nameof(url));
var parameters = new Dictionary<string, string>();
if (publicImages != null)
parameters.Add("public_images", $"{publicImages}".ToLower());
if (messagingEnabled != null)
parameters.Add("messaging_enabled", $"{messagingEnabled}".ToLower());
if (albumPrivacy != null)
parameters.Add("album_privacy", $"{albumPrivacy}".ToLower());
if (acceptedGalleryTerms != null)
parameters.Add("accepted_gallery_terms", $"{acceptedGalleryTerms}".ToLower());
if (showMature != null)
parameters.Add("show_mature", $"{showMature}".ToLower());
if (newsletterSubscribed != null)
parameters.Add("newsletter_subscribed", $"{newsletterSubscribed}".ToLower());
if (!string.IsNullOrWhiteSpace(username))
parameters.Add(nameof(username), username);
if (!string.IsNullOrWhiteSpace(bio))
parameters.Add(nameof(bio), bio);
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例14: PostReportRequest
internal HttpRequestMessage PostReportRequest(string url, Reporting reason)
{
if (string.IsNullOrEmpty(url))
throw new ArgumentNullException(nameof(url));
var parameters = new Dictionary<string, string>()
{
{ "reason", ((int)reason).ToString() }
};
var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters.ToArray())
};
return request;
}
示例15: HttpClient_PostAsync_ResponseContentAreEqual
public async Task HttpClient_PostAsync_ResponseContentAreEqual()
{
var fakeHttpMessageHandler = new FakeHttpMessageHandler();
var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) {Content = new StringContent("post response")};
fakeHttpMessageHandler.AddFakeResponse(new Uri("http://example.org/test"), fakeResponse);
var httpClient = new HttpClient(fakeHttpMessageHandler);
var parameters = new Dictionary<string, string> {{"Name", "bob"}};
var content = new FormUrlEncodedContent(parameters.ToArray());
var response = await httpClient.PostAsync("http://example.org/test", content);
var stringResponse = await response.Content.ReadAsStringAsync();
Assert.AreEqual("post response", stringResponse);
}