本文整理汇总了C#中Dictionary.Single方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Single方法的具体用法?C# Dictionary.Single怎么用?C# Dictionary.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Single方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunExistingScenarioActionView
public RunExistingScenarioActionView(Dictionary<Guid, string> allScenarios, Guid selectedScenario)
{
InitializeComponent();
foreach (var scenario in allScenarios)
{
listBox.Items.Add(scenario.Value);
}
listBox.SelectedIndexChanged += (o, e) =>
{
if (listBox.SelectedItem == null)
btSelect.Enabled = false;
else
{
btSelect.Enabled = true;
SelectedScenario = allScenarios.Single(x => x.Value == listBox.SelectedItem.ToString()).Key;
}
};
listBox.DoubleClick += (o, e) =>
{
if (listBox.SelectedItem != null)
{
SelectedScenario = allScenarios.Single(x => x.Value == listBox.SelectedItem.ToString()).Key;
DialogResult = DialogResult.OK;
}
};
}
示例2: LabyrinthChunkGenerator
public LabyrinthChunkGenerator(Dictionary<int, string> blocks, int width, int height, string seed)
: base(width, height, seed)
{
_doorId = blocks.Single(x => x.Value == "WoodenDoor").Key;
_floorId = blocks.Single(x => x.Value == "Stone").Key;
_wallId = blocks.Single(x => x.Value == "Stone").Key;
}
示例3: TestStringDictionary
public void TestStringDictionary()
{
var orig = new Dictionary<string,string> { {"abc","def" }};
var clone = Serializer.DeepClone(orig).Single();
MetaType[] types = RuntimeTypeModel.Default.GetTypes().Cast<MetaType>().ToArray();
Assert.AreEqual(orig.Single().Key, clone.Key);
Assert.AreEqual(orig.Single().Value, clone.Value);
}
示例4: DispatchCommand
internal static int DispatchCommand(Dictionary<CommandMetadata, object> commands, string[] args)
{
if (args == null || !args.Any()) throw new ShellHelpException();
var commandName = args.First().ToLower();
if (commands.All(meta => meta.Key.Name != commandName)) throw new ShellHelpException();
var command = commands.Single(meta => meta.Key.Name == commandName).Value;
var metadata = commands.Single(meta => meta.Key.Name == commandName).Key;
return RunCommand(command, metadata, args.Skip(1).ToArray());
}
示例5: BSPDungeonChunkGenerator
public BSPDungeonChunkGenerator(Dictionary<int, string> blocks, int width, int height, string seed, RoomGenerator roomGenerator)
: base(width, height, seed)
{
_chestId = blocks.Single(x => x.Value == "Chest").Key;
_doorId = blocks.Single(x => x.Value == "WoodenDoor").Key;
_floorId = blocks.Single(x => x.Value == "Stone").Key;
_wallId = blocks.Single(x => x.Value == "Stone").Key;
_roomGenerator = roomGenerator;
}
示例6: TeamBoxScore
/// <summary>
/// Initializes a new instance of the <see cref="TeamBoxScore" /> class.
/// </summary>
/// <param name="r">The SQLite query result row which contains the required information.</param>
public TeamBoxScore(DataRow r, Dictionary<int, TeamStats> tst)
{
ID = Convert.ToInt32(r["GameID"].ToString());
try
{
Team1ID = Convert.ToInt32(r["Team1ID"].ToString());
Team2ID = Convert.ToInt32(r["Team2ID"].ToString());
}
catch (Exception ex)
{
if (ex is ArgumentException || ex is KeyNotFoundException)
{
Team1ID = tst.Single(ts => ts.Value.Name == ParseCell.GetString(r, "T1Name")).Value.ID;
Team2ID = tst.Single(ts => ts.Value.Name == ParseCell.GetString(r, "T2Name")).Value.ID;
}
else
{
throw;
}
}
GameDate = Convert.ToDateTime(r["Date"].ToString());
SeasonNum = Convert.ToInt32(r["SeasonNum"].ToString());
IsPlayoff = Convert.ToBoolean(r["IsPlayoff"].ToString());
PTS1 = Convert.ToUInt16(r["T1PTS"].ToString());
REB1 = Convert.ToUInt16(r["T1REB"].ToString());
AST1 = Convert.ToUInt16(r["T1AST"].ToString());
STL1 = Convert.ToUInt16(r["T1STL"].ToString());
BLK1 = Convert.ToUInt16(r["T1BLK"].ToString());
TOS1 = Convert.ToUInt16(r["T1TOS"].ToString());
FGM1 = Convert.ToUInt16(r["T1FGM"].ToString());
FGA1 = Convert.ToUInt16(r["T1FGA"].ToString());
TPM1 = Convert.ToUInt16(r["T13PM"].ToString());
TPA1 = Convert.ToUInt16(r["T13PA"].ToString());
FTM1 = Convert.ToUInt16(r["T1FTM"].ToString());
FTA1 = Convert.ToUInt16(r["T1FTA"].ToString());
OREB1 = Convert.ToUInt16(r["T1OREB"].ToString());
FOUL1 = Convert.ToUInt16(r["T1FOUL"].ToString());
MINS1 = Convert.ToUInt16(r["T1MINS"].ToString());
PTS2 = Convert.ToUInt16(r["T2PTS"].ToString());
REB2 = Convert.ToUInt16(r["T2REB"].ToString());
AST2 = Convert.ToUInt16(r["T2AST"].ToString());
STL2 = Convert.ToUInt16(r["T2STL"].ToString());
BLK2 = Convert.ToUInt16(r["T2BLK"].ToString());
TOS2 = Convert.ToUInt16(r["T2TOS"].ToString());
FGM2 = Convert.ToUInt16(r["T2FGM"].ToString());
FGA2 = Convert.ToUInt16(r["T2FGA"].ToString());
TPM2 = Convert.ToUInt16(r["T23PM"].ToString());
TPA2 = Convert.ToUInt16(r["T23PA"].ToString());
FTM2 = Convert.ToUInt16(r["T2FTM"].ToString());
FTA2 = Convert.ToUInt16(r["T2FTA"].ToString());
OREB2 = Convert.ToUInt16(r["T2OREB"].ToString());
FOUL2 = Convert.ToUInt16(r["T2FOUL"].ToString());
MINS2 = Convert.ToUInt16(r["T2MINS"].ToString());
}
示例7: DugoutDungeonChunkGenerator
public DugoutDungeonChunkGenerator(Dictionary<int, string> blocks, int width, int height, string seed)
: base(width, height, seed)
{
// Adjust the size of the map, if it's smaller or bigger than the limits.
_rows = MathHelper.Clamp(height, 3, Height);
_columns = width; MathHelper.Clamp(width, 3, Width);
_chestId = blocks.Single(x => x.Value == "Chest").Key;
_doorId = blocks.Single(x => x.Value == "WoodenDoor").Key;
_floorId = blocks.Single(x => x.Value == "Stone").Key;
_wallId = blocks.Single(x => x.Value == "Stone").Key;
}
示例8: DateTimeViewModel
public DateTimeViewModel()
{
Days = new BindableCollection<int>();
Months = new Dictionary<int, string>();
Years = new BindableCollection<int>();
Hours = new BindableCollection<int>();
Minutes = new BindableCollection<int>();
for (var i = 0; i < 24; i++)
Hours.Add(i + 1);
for (var i = 0; i < 60; i++)
Minutes.Add(i);
for (var i = DateTime.Now.Year - 20; i < DateTime.Now.Year + 20; i++)
Years.Add(i);
SelectedYear = DateTime.Now.Year;
OnMonthsChanged();
SelectedDay = DateTime.Now.Day;
SelectedMonth = Months.Single(c => c.Key == DateTime.Now.Month);
SelectedHour = DateTime.Now.Hour;
SelectedMinute = DateTime.Now.Minute;
}
示例9: GetEndGameMessage
public static string GetEndGameMessage(Dictionary<ICompetitor, double> finalResult)
{
if (finalResult.Any(res => res.Value == 1.0))
{
return finalResult.Single(x => x.Value == 1.0).Key.Name + "\nWINS";
}
return "DRAW";
}
示例10: CreateOvalVariablesDocument
public oval_variables CreateOvalVariablesDocument(Dictionary<string, string[]> variableValues)
{
var newVariables = NewOvalVariables();
var externalVariables = OvalDefinitions.variables.OfType<VariablesTypeVariableExternal_variable>();
foreach (var variable in externalVariables)
{
var values = variableValues.Single(var => var.Key.Equals(variable.id)).Value;
newVariables.variables.Add(new OVAL.Variables.VariableType(variable.datatype, variable.id, values));
}
return newVariables;
}
示例11: DoAfterRead
protected override void DoAfterRead(Dictionary<string, HtmlDocument> docs)
{
// read topics
var doc = docs.Single().Value;
int i = 0;
while (doc.DocumentNode.SafeSelectNodes(String.Format("//input[@name='topic_delete_{0:D2}']", ++i)).Any())
{
string index = i.ToString("D2");
this.TopicList.Add(new Topic()
{
Name = (string)GetNodeValue(doc, _nameTag + index),
Regexes = GetNodeListValue(doc, _regexTag + index),
Description = GetNodeListValue(doc, _descTag + index).Cat(),
});
}
}
示例12: Solution
public static int Solution(int[] a)
{
Dictionary<int, int> dict = new Dictionary<int, int>();
for (int i = 0; i < a.Length; i++)
{
if (dict.ContainsKey(a[i]))
{
dict[a[i]]++;
}
else
{
dict[a[i]] = 1;
}
}
return dict.Single(p => p.Value == 1).Key;
}
示例13: SelectBrush
/// <summary>
/// Selects the Brush where the type matches from the Dictionary kept in the Legend.
/// </summary>
/// <param name="product"></param>
/// <param name="dict"></param>
/// <returns></returns>
public SolidBrush SelectBrush(PlacedProduct product, Dictionary<string, SolidBrush> dict)
{
SolidBrush brush;
try
{
CategoryModel Currentcat = product.Product.ProductCategory;
if (Currentcat.IsSubcategoryFrom > -1 || Currentcat.IsSubcategoryFrom == null) // is a subcategory
{
// gets the main category id
int MainId = (int) Currentcat.IsSubcategoryFrom;
// linq select category with the current id
var selectedcategory2 = CategoryModel.List
.Where(c => c.CatId == MainId)
.Select(c => c)
.ToList();
CategoryModel Main = selectedcategory2[0];
// gets the value (color) from the Main productcategory
brush = new SolidBrush(Main.Colour);
}
else // is a maincategory
{
// give the color from the main category
brush = dict.Single(pair => pair.Key.Equals(product.Product.Category)).Value;
}
}
catch (InvalidOperationException e)
{
// This means that the type is not found in the dictionary, and so I will set the Brush to Black
brush = new SolidBrush(Color.Gray);
}
return brush;
}
示例14: GetPostedFormInfo
/// <summary>
/// Checks the request and query strings to see if it matches the definition of having a Surface controller
/// posted value, if so, then we return a PostedDataProxyInfo object with the correct information.
/// </summary>
/// <param name="requestContext"></param>
/// <returns></returns>
private static PostedDataProxyInfo GetPostedFormInfo(RequestContext requestContext)
{
if (requestContext.HttpContext.Request.RequestType != "POST")
return null;
//this field will contain a base64 encoded version of the surface route vals
if (requestContext.HttpContext.Request["uformpostroutevals"].IsNullOrWhiteSpace())
return null;
var encodedVal = requestContext.HttpContext.Request["uformpostroutevals"];
var decryptedString = encodedVal.DecryptWithMachineKey();
var parsedQueryString = HttpUtility.ParseQueryString(decryptedString);
var decodedParts = new Dictionary<string, string>();
foreach (var key in parsedQueryString.AllKeys)
{
decodedParts[key] = parsedQueryString[key];
}
//validate all required keys exist
//the controller
if (!decodedParts.Any(x => x.Key == ReservedAdditionalKeys.Controller))
return null;
//the action
if (!decodedParts.Any(x => x.Key == ReservedAdditionalKeys.Action))
return null;
//the area
if (!decodedParts.Any(x => x.Key == ReservedAdditionalKeys.Area))
return null;
////the controller type, if it contains this then it is a plugin controller, not locally declared.
//if (decodedParts.Any(x => x.Key == "t"))
//{
// return new PostedDataProxyInfo
// {
// ControllerName = requestContext.HttpContext.Server.UrlDecode(decodedParts.Single(x => x.Key == "c").Value),
// ActionName = requestContext.HttpContext.Server.UrlDecode(decodedParts.Single(x => x.Key == "a").Value),
// Area = requestContext.HttpContext.Server.UrlDecode(decodedParts.Single(x => x.Key == "ar").Value),
// ControllerType = requestContext.HttpContext.Server.UrlDecode(decodedParts.Single(x => x.Key == "t").Value)
// };
//}
foreach (var item in decodedParts.Where(x => !new string[] {
ReservedAdditionalKeys.Controller,
ReservedAdditionalKeys.Action,
ReservedAdditionalKeys.Area }.Contains(x.Key)))
{
// Populate route with additional values which aren't reserved values so they eventually to action parameters
requestContext.RouteData.Values.Add(item.Key, item.Value);
}
//return the proxy info without the surface id... could be a local controller.
return new PostedDataProxyInfo
{
ControllerName = requestContext.HttpContext.Server.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Controller).Value),
ActionName = requestContext.HttpContext.Server.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Action).Value),
Area = requestContext.HttpContext.Server.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Area).Value),
};
}
示例15: Weave
public override void Weave(
TypeDefinition typeDef,
AssemblyDefinition assemblyDefinition,
MapDefinition mapDefinition,
Dictionary<string, List<MapDefinition>> assemblyMapDefinitions,
Dictionary<string, AssemblyDefinition> assemblyDefinitions) {
var boolTypeDef = typeDef.Module.Import(typeof(bool));
foreach (var columnDef in
mapDefinition.ColumnDefinitions.Where(
c => c.Relationship == RelationshipType.ManyToOne || c.Relationship == RelationshipType.OneToOne)) {
// remember the property may be defined on a parent class
var propDef = this.GetProperty(typeDef, columnDef.Name);
// add a field with DbType and DbName
TypeReference fkTypeReference;
var fkPkType = columnDef.DbType.GetCLRType();
if (fkPkType.IsValueType) {
fkTypeReference = typeDef.Module.Import(typeof(Nullable<>).MakeGenericType(fkPkType));
}
else {
fkTypeReference = typeDef.Module.Import(fkPkType);
}
var fkField = new FieldDefinition(columnDef.DbName, FieldAttributes.Public, fkTypeReference);
if (propDef.DeclaringType.Fields.Any(f => f.Name == columnDef.DbName)) {
continue; // already done something here!
}
this.MakeNotDebuggerBrowsable(typeDef.Module, fkField);
propDef.DeclaringType.Fields.Add(fkField);
// override the set method to set to null
propDef.SetMethod.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Initobj, fkTypeReference));
propDef.SetMethod.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Ldflda, fkField));
propDef.SetMethod.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Ldarg_0));
// override the get method to access this field if null and create a new instance
// TODO solve for non auto properties
if (!propDef.GetMethod.Body.Variables.Any()) {
// Release code is different to debug code!
propDef.GetMethod.Body.Variables.Add(new VariableDefinition(propDef.PropertyType));
}
propDef.GetMethod.Body.Variables.Add(new VariableDefinition(propDef.PropertyType));
propDef.GetMethod.Body.Variables.Add(new VariableDefinition(boolTypeDef));
propDef.GetMethod.Body.InitLocals = true;
//propDef.GetMethod.Body.Instructions.Clear();
var backingField = this.GetBackingField(propDef);
var il = propDef.GetMethod.Body.Instructions;
var lastInstr = il[0];
var index = 0;
// first bit does the null/hasValue checks on the backing fields
il.Insert(index++, Instruction.Create(OpCodes.Ldarg_0));
il.Insert(index++, Instruction.Create(OpCodes.Ldfld, backingField));
il.Insert(index++, Instruction.Create(OpCodes.Brtrue, lastInstr));
if (fkPkType.IsValueType) {
il.Insert(index++, Instruction.Create(OpCodes.Ldarg_0));
il.Insert(index++, Instruction.Create(OpCodes.Ldflda, fkField));
il.Insert(
index++,
Instruction.Create(
OpCodes.Call,
MakeGeneric(
typeDef.Module.Import(fkTypeReference.Resolve().GetMethods().Single(m => m.Name == "get_HasValue")),
typeDef.Module.Import(fkPkType))));
}
else {
il.Insert(index++, Instruction.Create(OpCodes.Ldarg_0));
il.Insert(index++, Instruction.Create(OpCodes.Ldfld, fkField));
}
il.Insert(index++, Instruction.Create(OpCodes.Brfalse, lastInstr));
// if we have a pk but no ref we create a new instance with the primary key set
il.Insert(index++, Instruction.Create(OpCodes.Ldarg_0));
il.Insert(
index++,
Instruction.Create(OpCodes.Newobj, typeDef.Module.Import(propDef.PropertyType.Resolve().GetConstructors().First())));
il.Insert(index++, Instruction.Create(OpCodes.Stloc_0));
il.Insert(index++, Instruction.Create(OpCodes.Ldloc_0));
il.Insert(index++, Instruction.Create(OpCodes.Ldarg_0));
if (fkPkType.IsValueType) {
il.Insert(index++, Instruction.Create(OpCodes.Ldflda, fkField));
il.Insert(
index++,
Instruction.Create(
OpCodes.Call,
typeDef.Module.Import(
MakeGeneric(
fkField.FieldType.Resolve().GetMethods().Single(m => m.Name == "get_Value"),
typeDef.Module.Import(fkPkType)))));
var fkMapDef = assemblyMapDefinitions.SelectMany(am => am.Value).First(m => m.TypeFullName == columnDef.TypeFullName);
var assemblyDef = assemblyDefinitions.Single(ad => ad.Value.FullName == fkMapDef.AssemblyFullName).Value;
var fkMapTypeRef = GetTypeDefFromFullName(columnDef.TypeFullName, assemblyDef);
il.Insert(
//.........这里部分代码省略.........