本文整理汇总了C#中List.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# List.ToDictionary方法的具体用法?C# List.ToDictionary怎么用?C# List.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.ToDictionary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildExpressionTree
public ExpressionTree BuildExpressionTree(List<AssignStatement> expressions, string calcForWire)
{
Dictionary<string, AssignStatement> variableMapping = expressions.ToDictionary(x => x.Variable.Identifier, y => y);
Dictionary<AssignStatement, IEnumerable<VariableExpression>> dependencyMapping = expressions.ToDictionary(x => x, y => y.Value.GetDependencies());
return CreateFor(calcForWire, variableMapping, dependencyMapping, new Dictionary<string, ExpressionTree>());
}
示例2: ControlFlowGraph2
public ControlFlowGraph2(MethodBody body)
{
_body = body;
_basicBlocks = new ControlFlowGraph(body).ToList();
_entries = _basicBlocks.ToDictionary(b => b.Entry, b => b);
_exits = _basicBlocks.ToDictionary(b => b.Exit, b => b);
_entryInstructions = _basicBlocks.Select(b => b.Entry).ToList();
IncludeExceptionHandlers(body);
}
示例3: XMLOpcodeLookup
public XMLOpcodeLookup(XDocument document)
{
XContainer root = document.Element("BlamScript");
// Script execution types
var scriptTypes = from element in root.Element("scriptTypes").Descendants("type")
select new
{
Opcode = (ushort)XMLUtil.GetNumericAttribute(element, "opcode"),
Name = XMLUtil.GetStringAttribute(element, "name")
};
_scriptTypeNameLookup = scriptTypes.ToDictionary(t => t.Opcode, t => t.Name);
_scriptTypeOpcodeLookup = scriptTypes.ToDictionary(t => t.Name, t => t.Opcode);
// Value types
var valueTypes = new List<ScriptValueType>();
foreach (var element in root.Element("valueTypes").Descendants("type"))
{
var name = XMLUtil.GetStringAttribute(element, "name");
var opcode = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
var size = XMLUtil.GetNumericAttribute(element, "size");
var quoted = XMLUtil.GetBoolAttribute(element, "quoted", false);
var tag = XMLUtil.GetStringAttribute(element, "tag", null);
valueTypes.Add(new ScriptValueType(name, opcode, size, quoted, tag));
}
_typeLookupByOpcode = valueTypes.ToDictionary(t => t.Opcode);
_typeLookupByName = valueTypes.ToDictionary(t => t.Name);
// Functions
foreach (var element in root.Element("functions").Descendants("function"))
{
var name = XMLUtil.GetStringAttribute(element, "name");
if (name == "")
continue;
var opcode = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
var returnType = XMLUtil.GetStringAttribute(element, "returnType", "void");
var flags = (uint)XMLUtil.GetNumericAttribute(element, "flags", 0);
var parameterTypes = element.Descendants("arg").Select(e => XMLUtil.GetStringAttribute(e, "type")).ToArray();
var info = new ScriptFunctionInfo(name, opcode, returnType, flags, parameterTypes);
List<ScriptFunctionInfo> functions;
if (!_functionLookupByName.TryGetValue(name, out functions))
{
functions = new List<ScriptFunctionInfo>();
_functionLookupByName[name] = functions;
}
functions.Add(info);
_functionLookupByOpcode[opcode] = info;
}
}
示例4: LoadDrinks
public DrinksContainer LoadDrinks(string source)
{
using (StringReader stringReader = new StringReader(source))
{
List<Drink> trainingSet = new List<Drink>();
string line = stringReader.ReadLine();
string[] columnNames = line.Split(';').Skip(COLUMNS_TO_SKIP).ToArray();
while ((line = stringReader.ReadLine()) != null)
{
string[] values = line.Split(';');
int id = int.Parse(values[0]);
string drinkName = values[1],
url = values[2],
imageUrl = values[3];
double[] trainingRow = new double[values.Length - COLUMNS_TO_SKIP];
for (int i = 0; i < trainingRow.Length - 1; i++)
{
trainingRow[i] = double.Parse(values[i + COLUMNS_TO_SKIP], System.Globalization.CultureInfo.InvariantCulture);
}
trainingSet.Add(new Drink(id, drinkName, url, trainingRow, imageUrl));
}
return new DrinksContainer(trainingSet.ToDictionary(r => r.ID, r => r), columnNames);
}
}
示例5: AppenderConfigProperties
public AppenderConfigProperties(List<pt.sapo.gis.trace.configuration.Appender.Property> properties)
{
if (properties != null)
{
this.properties = properties.ToDictionary(p => p.Name, p => p.Content);
}
}
示例6: ActualizarPantalla
private void ActualizarPantalla(List<Encomienda> encomienda)
{
var diccionarioDeEncimiendas = new Dictionary<int, Encomienda>();
#region Cargar el diccionario a mostrar en la grilla
if (encomienda == null)
{
}
else
{
//El datasource se carga con la lista de pasajes recibida por parámetro
diccionarioDeEncimiendas = encomienda.ToDictionary(e => e.ID, e => e);
}
//Muestra en la grilla el contenido de los pasajes que se encuentran cargados en el diccionario
var bind = diccionarioDeEncimiendas.Values.Select(e => new
{
Codigo_Pasaje = e.Codigo_Encomienda,
Numero_Butaca = e.KG,
Precio = e.Precio
});
#endregion
DgvEncomiendas.DataSource = bind.ToList();
AgregarBotonesDeColumnas();
DgvEncomiendas.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
}
示例7: Refresh
public bool Refresh(ProviderMember aMember, List<ProviderCategory> categoryList)
{
CategoryList = new List<SelectList>();
AlternateCategoryMapList = new List<AlternateCategoryMapVM>();
List<KeyValuePair<long, string>> ddList = new List<KeyValuePair<long, string>>();
ddList.Add(_nullCategory);
ddList.AddRange(categoryList.ToDictionary(aCategory => aCategory.Id.Value, aCategory => aCategory.Title));
foreach (ProviderAlternateCategoryId altCategory in aMember.AlternateCategoryList)
{
if(!string.IsNullOrEmpty(altCategory.DisplayName))
{
long selectedCatId = altCategory.CategoryId ?? -1;
AlternateCategoryMapList.Add(new AlternateCategoryMapVM
{
AlternateTitle = altCategory.DisplayName,
AlternateId = altCategory.AlternateId,
MapId = selectedCatId
});
CategoryList.Add(new SelectList(ddList, "key", "value", selectedCatId));
}
}
return true;
}
示例8: GetInstanceStates
private void GetInstanceStates()
{
var loadBalancer = command.Parameters[0];
var elb = new ELB();
this.states = elb.InstanceState(loadBalancer);
this.stateMap = states.ToDictionary(k => k.InstanceId, v => v.State);
}
示例9: SetExecuted
private static void SetExecuted(List<MigrationInfo> migrations)
{
MigrationLogic.EnsureMigrationTable<SqlMigrationEntity>();
var first = migrations.FirstOrDefault();
var executedMigrations = Database.Query<SqlMigrationEntity>().Select(m => m.VersionNumber).OrderBy().ToList().Where(d => first == null || first.Version.CompareTo(d) <= 0).ToList();
var dic = migrations.ToDictionary(a => a.Version, "Migrations in folder");
foreach (var ver in executedMigrations)
{
var m = dic.TryGetC(ver);
if (m != null)
m.IsExecuted = true;
else
migrations.Add(new MigrationInfo
{
FileName = null,
Comment = ">> In Database Only <<",
IsExecuted = true,
Version = ver
});
}
migrations.Sort(a => a.Version);
}
示例10: CountryCodeHelper
public CountryCodeHelper(List<Country> countries)
{
_countryCodes = countries.ToDictionary(x => x.Name, x => x.CountryCode);
_currencyCodes = countries
.Distinct((x, y) => x.CountryCode == y.CountryCode)
.ToDictionary(x => x.CountryCode, x => x.CurrencyCode);
}
示例11: ActualizarPantalla
private void ActualizarPantalla(List<Pasaje> pasajes)
{
var diccionarioDePasajes = new Dictionary<int, Pasaje>();
#region Cargar el diccionario a mostrar en la grilla
if (pasajes == null)
{
}
else
{
//El datasource se carga con la lista de pasajes recibida por parámetro
diccionarioDePasajes = pasajes.ToDictionary(p => p.ID, p => p);
}
//Muestra en la grilla el contenido de los pasajes que se encuentran cargados en el diccionario
var bind = diccionarioDePasajes.Values.Select(p => new
{
Codigo_Pasaje = p.Codigo_Pasaje,
Pasajero = p.ID_Cliente,
Numero_Butaca = p.ID_Butaca,
Precio = p.Precio
});
#endregion
DgvPasaje.DataSource = bind.ToList();
AgregarBotonesDeColumnas();
DgvPasaje.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
}
示例12: Index
public ActionResult Index()
{
var currentUser = this.userService.GetCurrentUser();
var sharedCourses = this.storage.GetCourses(currentUser.Id);
var courses = this.storage.GetCourses(User.Identity.Name);
var all = sharedCourses.Union(courses);
var owners = all.Select(i => i.Owner).Distinct().ToList();
var users = new List<User>();
foreach (var owner in owners)
{
var copy = owner;
users.AddRange(this.userService.GetUsers(i => i.Username == copy));
}
var dic = users.ToDictionary(i => i.Username, j => j.Username);
var viewCourses = all.Select(i => new ViewCourseModel
{
Id = i.Id,
Name = i.Name,
Created = i.Created,
Updated = i.Updated,
Locked = i.Locked ?? false,
Shared = i.Owner != currentUser.Username,
OwnerName = dic.ContainsKey(i.Owner) ? dic[i.Owner] : i.Owner,
UpdatedByName = i.UpdatedBy
});
return View(viewCourses.OrderByDescending(i => i.Updated).AsEnumerable());
}
示例13: Rulebook
public Rulebook(List<IRule> rules, List<IModifier> modifiers, Type interactionType)
{
this.interactionType = interactionType;
foreach (IRule rule in rules)
{
string interaction = rule.Interaction;
if (!this.rules.ContainsKey(interaction)) this.rules.Add(interaction, new Section(rule));
else this.rules[interaction].Add(rule);
}
this.Modifiers = modifiers.ToDictionary<IModifier, string>(i => i.Target);
// Merge sections that descend from other sections. This means that the hierarchy does not
// need to be negotiated when looking up rules in a section. For example, if you have some
// generic "Move" rules and then you have a specific "Move.Run" rule section, the "Move.Run"
// will have all of the rules in "Move" added to it. Since rules are selected in list order
// the specific "Move.Run" rules will be checked first before moving on to the generic "Move" rules.
foreach (KeyValuePair<string, Section> kvp in this.rules)
{
string interaction = kvp.Key;
int trim = interaction.LastIndexOf('.');
if (trim > 0)
{
interaction = interaction.Remove(trim);
if (this.rules.ContainsKey(interaction)) kvp.Value.Merge(this.rules[interaction]);
}
}
}
示例14: GetDrawInstructions
public IEnumerable<MouseDragAction> GetDrawInstructions(List<ColorSpot> colorPalette, IDictionary<string, string> options = null, IBrushChanger brushChanger = null)
{
if (!colorPalette.Any())
{
throw new ArgumentException("I need some colors. Give me some colors. Thanks!");
}
var output = new List<MouseDragAction>();
var colorPixels = colorPalette.ToDictionary(colorSpot => colorSpot, colorSpot => new List<Point>());
using (var bitmap = new Bitmap(_bitmapPath))
{
bitmap.LoopThroughPixels((point, color) =>
{
var selectedColor = colorPalette.OrderBy(c => c.Color.DifferenceTo(color)).FirstOrDefault();
if (selectedColor == null || !colorPixels.ContainsKey(selectedColor) ||
selectedColor.Color.DifferenceTo(Color.White) == 0)
{
return;
}
colorPixels[selectedColor].Add(point);
});
}
foreach (var colorPixel in colorPixels.Where(colorPixel => colorPixel.Value.Any()))
{
output.Add(new MouseDragAction(new List<Point> { colorPixel.Key.Point }, true, colorPixel.Key.Color));
var actions = colorPixel.Value.Select(point => new MouseDragAction(new List<Point> { point })).ToList();
if (options.GetBoolValueOrDefault("MixPoints", false))
{
actions = actions.Shuffle().ToList();
}
output.AddRange(actions);
}
return output.ToArray();
}
示例15: GetDistrictIndicatorTrees
/// <summary>
/// NEED TO REFACTOR THIS TO A REPORT
/// </summary>
/// <param name="interventionTypeId"></param>
/// <param name="year"></param>
/// <param name="diseaseId"></param>
/// <param name="customAggRule"></param>
/// <returns></returns>
public List<AdminLevelIndicators> GetDistrictIndicatorTrees(int interventionTypeId, int year, int diseaseId, Func<AggregateIndicator, object, object> customAggRule, int reportingLevel)
{
List<AdminLevelIndicators> list = new List<AdminLevelIndicators>();
Dictionary<int, AdminLevelIndicators> dic = new Dictionary<int, AdminLevelIndicators>();
OleDbConnection connection = new OleDbConnection(DatabaseData.Instance.AccessConnectionString);
using (connection)
{
connection.Open();
OleDbCommand command = new OleDbCommand();
list = GetAdminLevels(command, connection, false);
dic = list.ToDictionary(n => n.Id, n => n);
AddIntvIndicators(interventionTypeId, year, dic, command, connection, customAggRule);
AddSurveyIndicators(diseaseId, year, dic, command, connection, customAggRule);
AddDistroIndicators(diseaseId, year, dic, command, connection, customAggRule);
}
var rootNodes = new List<AdminLevelIndicators>();
foreach (var node in list)
{
if (node.ParentId.HasValue && node.ParentId.Value > 0)
{
AdminLevelIndicators parent = dic[node.ParentId.Value];
node.Parent = parent;
parent.Children.Add(node);
}
else
{
rootNodes.Add(node);
}
}
return list.Where(a => a.LevelNumber == reportingLevel).ToList();
}