本文整理汇总了C#中System.Collections.Generic.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.ToDictionary方法的具体用法?C# System.Collections.Generic.ToDictionary怎么用?C# System.Collections.Generic.ToDictionary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.ToDictionary方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_get_dictionary_of_property_values
public void Should_get_dictionary_of_property_values()
{
var something = new {Value = 123, Another = "Test"};
IDictionary<string, object> dictionary = something.ToDictionary();
dictionary["Value"].ShouldEqual(123);
dictionary["Another"].ShouldEqual("Test");
}
示例2: Initialize
public static void Initialize()
{
var initialState = new[]
{
new Stall {Id = 1, Available = true, Location = "asynchrony"},
new Stall {Id = 2, Available = true, Location = "asynchrony"},
new Stall {Id = 3, Available = true, Location = "asynchrony"},
};
_cache = initialState.ToDictionary(s => s.Id);
}
示例3: should_read_from_cache_when_no_update_in_po_file
public void should_read_from_cache_when_no_update_in_po_file()
{
var parser = new Mock<IPoFileParser>();
var expectedI18NMessages = new[] { new I18NMessage("translation key", "translation key") };
var localeEnUsMessagesPo = Path.Combine(TestHelper.GetRuntimePath(),"locale\\en-US\\messages.po");
parser.Setup(p => p.Parse(localeEnUsMessagesPo)).Returns(expectedI18NMessages.ToDictionary(d=> d.MsgId));
var i18NMessagesCache = new GenericCache<IDictionary<string, I18NMessage>>();
var actualI18NMessages = i18NMessagesCache.Get("en-US", () => parser.Object.Parse(localeEnUsMessagesPo));
VerifyResult(expectedI18NMessages, actualI18NMessages);
}
示例4: should_return_correct_translation_value_given_correct_key
public void should_return_correct_translation_value_given_correct_key()
{
var parser = new Mock<IPoFileParser>();
var expectedI18NMessages = new[] { new I18NMessage("translation key", "translation vlaue") };
var localeEnUsMessagesPo = Path.Combine(TestHelper.GetRuntimePath(), "locale\\en-US\\messages.po");
parser.Setup(p =>p.Parse(localeEnUsMessagesPo)).Returns(expectedI18NMessages.ToDictionary(d => d.MsgId));
var i18NMessagesCache = new GenericCache<IDictionary<string, I18NMessage>>();
var result = new LocalizingService(i18NMessagesCache, TestHelper.GetRuntimePath(), parser.Object)
.GetText("translation key", new []{"en-US"});
Assert.Equal("translation vlaue", result);
}
示例5: GetDictionary
public static Dictionary<string, Creature> GetDictionary()
{
var entries = new[]
{
new Creature()
{
Name ="Rat",
Health =10,
Damage =3
},
new Creature()
{
Name = "Kobold",
Health = 15,
Damage = 5
}
};
return entries.ToDictionary(item => item.Name);
}
示例6: GenerateUsername
public async Task<string> GenerateUsername(string givenName, string surName) //100%
{
var parameters =
new[]
{
new { Key = "givenName", Value = givenName },
new { Key = "surName", Value = surName }
};
var y = await Api("usernamegenerator/", parameters.ToDictionary(e => e.Key, e => e.Value));
var x = JsonConvert.DeserializeAnonymousType(y, new { username = string.Empty });
return x.username;
}
示例7: Login
public async Task<Profile> Login(Device device, string username, string password) //99*%
{
//todo sort out returns
var parameters = new[]
{
new { Key = "password", Value = password}
};
var y = await Api("profile/login/" + username, parameters.ToDictionary(e => e.Key, e => e.Value));
var x = JsonConvert.DeserializeObject<LoginResponse>(y);
return null; //Don't know what data returns when logged is SUCCESSFULL - Would need ProfileID to get the profile.
//EG "\n{\"authenticated\":false,\"verificationRequired\":false,\"forcePasswordReset\":false}"
}