本文整理汇总了C#中ICollection.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.ToDictionary方法的具体用法?C# ICollection.ToDictionary怎么用?C# ICollection.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.ToDictionary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Calculator
public Calculator(ICollection<IExportFactory<IOperation, OperationMetadata>> operationFactories, IParser parser)
{
this.parser = parser;
this.OperationsDictionary = operationFactories.ToDictionary(
e => e.Metadata.Operation,
e => e.CreateExport().Value);
}
示例2: ATS
public ATS(ICollection<IPort> ports, ILogger logger)
{
this._Logger = logger;
this._RoutingPorts = new Dictionary<PhoneNumber, IPort>();
this._Terminals = new List<ITerminal>();
this._PortsIsAvailable = ports.ToDictionary(port => port, port => true);
this._ConnectingCalls = new List<CallInfo>();
this._ActiveCalls = new List<CallInfo>();
}
示例3: SetMethodTasks
public void SetMethodTasks(ICollection<XunitTestMethodTask> value)
{
if (value == null || value.Count == 0)
{
classResult = TaskResult.Inconclusive;
methodTasks = new Dictionary<string, XunitTestMethodTask>();
}
else
{
methodTasks = value.ToDictionary(x => x.ShortName);
}
}
示例4: Entry
public Entry(ICollection<Field> fields)
{
if (fields == null)
throw new ArgumentNullException("fields");
Icon = new IconData();
_original = fields;
_fields = fields.ToDictionary(
x => x.Name, x => x.Clone());
_protects = new EntryProtects(_fields);
}
示例5: Bfs
static IDictionary<string, int> Bfs(string start, ICollection<string> friends)
{
IDictionary<string, int> results = friends.ToDictionary(friend => friend, friend => -1);
if (!neighbors.ContainsKey(start))
return results;
var queue = new Queue<string>();
visited.Add(start);
queue.Enqueue(start);
int level = 0;
while (queue.Count != 0)
{
var nextQueue = new Queue<string>();
level++;
while (queue.Count != 0)
{
string current = queue.Dequeue();
foreach (string neighbor in neighbors[current])
{
if (visited.Contains(neighbor))
continue;
if (results.ContainsKey(neighbor) && results[neighbor] == -1)
results[neighbor] = level;
visited.Add(neighbor);
nextQueue.Enqueue(neighbor);
}
}
queue = nextQueue;
}
return results;
}
示例6: GenerateStateGraph
private static void GenerateStateGraph(ICollection<State> states, TextWriter output)
{
int index = 0;
var stateNames = states.ToDictionary(s => s, s => "S" + index++);
output.WriteLine("digraph {");
foreach (var state in states)
{
output.WriteLine(" {0} [label=\"{1}\",shape={2}];", stateNames[state], state.Name, state.IsTerminal ? "box" : "ellipse");
foreach (var nextState in state.NextStates)
{
output.WriteLine(" {0} -> {1};", stateNames[state], stateNames[nextState]);
}
if (state.InnerState != null)
{
output.WriteLine(" {0} -> {1} [style=dotted];", stateNames[state], stateNames[state.InnerState]);
}
}
output.WriteLine("}");
}
示例7: ResolveConflicts
private void ResolveConflicts(ICollection<ClientChange> localChanges, ICollection<ClientChange> remoteChanges)
{
var localByName = localChanges.ToDictionary(local => local.FullName);
var remoteByName = remoteChanges.ToDictionary(remote => remote.FullName);
ChangeNode.FromItems(localChanges).PreservingConflicts(ChangeNode.FromItems(remoteChanges), (local, remote) =>
{
if (local.Type != ChangeType.Add)
return;
if (localByName[local.FullName].InvitationId.HasValue &&
localByName[local.FullName].InvitationId.Value != 0)
{
// Cannot resolve a conflict on a shared folder. Just delete our copy.
Utilities.DeleteDirectoryRecursive(GetLocalFullName(local.FullName));
return;
}
if (!local.IsFolder && !remote.IsFolder &&
localByName[local.FullName].Hash == remoteByName[remote.FullName].Hash)
{
// The two copies are actually identical. Just delete our copy.
SalvageAndDeleteDocument(localByName[local.FullName].Hash, GetLocalFullName(local.FullName));
return;
}
var localClientChange = localByName[local.FullName];
string parentPrefix = GetLocalFullName(local.Parent.FullName) + "\\";
string fullDisplayName = parentPrefix + localClientChange.DisplayName;
string newFullDisplayName;
do
{
newFullDisplayName = parentPrefix + Utilities.GenerateNewName(
localClientChange.DisplayName,
!local.IsFolder,
_state.ClientName + "'s conflicted copy " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff")
);
} while (System.IO.File.Exists(newFullDisplayName) || System.IO.Directory.Exists(newFullDisplayName));
MoveFileOrDirectory(fullDisplayName, newFullDisplayName);
});
}
示例8: Apply
public void Apply(ICollection<ClientChange> changes)
{
var clientChanges = changes.ToDictionary(change => change.FullName);
var rootNode = ChangeNode.FromItems(changes);
if (rootNode.Nodes == null || rootNode.Nodes.Count == 0)
{
// This shouldn't happen.
changes.Clear();
return;
}
// Fix up first-level nodes.
foreach (var node in rootNode.Nodes.Values)
node.Type = ChangeType.None;
Apply(_state.Root, rootNode, clientChanges);
if (rootNode.Nodes.Count == 0)
{
// Signal that there are no more changes to apply.
changes.Clear();
}
}
示例9: CellsToRow
public Dictionary<string, ICell> CellsToRow(ICollection<ICell> cells)
{
return cells.ToDictionary(
cell => Headers[cell.ColumnNum - 1],
cell => cell);
}
示例10: ValidateTransactionInventory
public SystemResponse<Dictionary<int, bool>> ValidateTransactionInventory(ICollection<PersonalProtectiveEquipmentTransaction> transactions)
{
var validationResult = new SystemResponse<Dictionary<int,bool>>(new Dictionary<int,bool>());
//initialize a result for all transactions
validationResult.result = transactions.ToDictionary(c => c.Id,c => true);
//get the inventory by filtering out on the ids
var transactionTypes = GetTransactionTypes();
//current method gets all inventory
var currentInventory = GetPersonalProtectiveEquipmentCategoryTypeModelInventorys();
foreach (var transaction in transactions) { transaction.TransactionType = transactionTypes.Single(c => c.Id == transaction.TransactionTypeId); }
//group all transactions by model id
var transactionsGroupedByPPEModelId = transactions.GroupBy(c => c.PersonalProtectiveEquipmentCategoryTypeModelId);
foreach (var transactionGrouping in transactionsGroupedByPPEModelId)
{
int inventoryOfModel = currentInventory.Single(c => c.PersonalProtectiveEquipmentCategoryTypeModelId ==
transactionGrouping.First().PersonalProtectiveEquipmentCategoryTypeModelId).Quantity;
//check if transactions are mixed incoming & outgoing
if (transactionGrouping.Any(c => c.TransactionType.TransactionDirectionId == TransactionDirectionIncomingId) &&
transactionGrouping.Any(d => d.TransactionType.TransactionDirectionId == TransactionDirectionOutgoingId))
{
var incomingTransactions = transactionGrouping.Where(c => c.TransactionType.TransactionDirectionId == TransactionDirectionIncomingId);
foreach (var incomingTransaction in incomingTransactions)
{
inventoryOfModel += incomingTransaction.Quantity;
}
var outgoingTransactions = transactionGrouping.Where(c => c.TransactionType.TransactionDirectionId == TransactionDirectionOutgoingId);
foreach (var outgoingTransaction in outgoingTransactions)
{
if (outgoingTransaction.Quantity <= inventoryOfModel)
{
inventoryOfModel -= outgoingTransaction.Quantity;
}
else
{
validationResult.result[outgoingTransaction.Id] = false;
}
}
}
else
{
var outgoingTransactions = transactionGrouping.Where(c => c.TransactionType.TransactionDirectionId == TransactionDirectionOutgoingId);
foreach (var outgoingTransaction in outgoingTransactions)
{
if (outgoingTransaction.Quantity <= inventoryOfModel)
{
inventoryOfModel -= outgoingTransaction.Quantity;
}
else
{
validationResult.result[outgoingTransaction.Id] = false;
}
}
}
}
return validationResult;
}
示例11: SelectDynamic
static IQueryable SelectDynamic(IQueryable source, ICollection<QueryColumn> columns)
{
var dynamicType = LinqRuntimeTypeBuilder.GetDynamicType(columns.ToDictionary(c => c.Name, c => c.ColumnType));
var sourceItem = Expression.Parameter(source.ElementType, "t");
var bindings = dynamicType.GetFields().Select(p => Expression.Bind(p, Expression.Property(sourceItem, p.Name))).OfType<MemberBinding>();
var selector = Expression.Lambda(Expression.MemberInit(Expression.New(dynamicType.GetConstructor(Type.EmptyTypes)), bindings), sourceItem);
return source.Provider.CreateQuery(Expression.Call(typeof(Queryable), "Select", new Type[] { source.ElementType, dynamicType }, Expression.Constant(source), selector));
}
示例12: _convertTypes
protected Dictionary<string, SqlColumnType> _convertTypes(ICollection<Dictionary<string, object>> sysobjectsInfos)
{
return sysobjectsInfos.ToDictionary(
row => row["COLUMN_NAME"].ToString(),
row => _determineType(row));
}
示例13: GetCreateHelperFunc
private static Func<XSerializerXmlReader, IHelper> GetCreateHelperFunc(Type type, ICollection<SerializableProperty> serializableProperties)
{
if (type.IsAbstract)
{
throw new InvalidOperationException("Cannot create instance of abstract type: " + type);
}
var properties = type.GetProperties();
var validConstructors =
type.GetConstructors()
.Where(constructor =>
constructor.GetParameters()
.All(parameter =>
(parameter.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault
|| properties.Any(
property =>
property.Name.ToLower() == parameter.Name.ToLower()
&& (parameter.ParameterType.IsAssignableFrom(property.PropertyType)
|| IsIListParameterAndReadOnlyCollectionProperty(parameter, property)
|| IsIDictionaryParameterAndReadOnlyDictionaryProperty(parameter, property)))))
.ToArray();
var caseSensitiveSerializableProperties = serializableProperties.ToDictionary(p => p.Name);
var textNodeProperty = serializableProperties.SingleOrDefault(p => p.NodeType == NodeType.Text);
var attributeProperties = serializableProperties.Where(p => p.NodeType == NodeType.Attribute).ToDictionary(p => p.Name);
if (validConstructors.Length == 0)
{
if (type.IsValueType)
{
return reader => new DefaultConstructorHelper(
() => (T)FormatterServices.GetUninitializedObject(typeof(T)),
caseSensitiveSerializableProperties,
textNodeProperty,
attributeProperties,
reader);
}
throw new InvalidOperationException("No valid constructors were found for type: " + type);
}
if (validConstructors.Length == 1 && validConstructors[0].GetParameters().Length == 0)
{
var ctor = validConstructors[0];
var lambda = Expression.Lambda<Func<T>>(Expression.Convert(Expression.New(ctor), typeof(T)));
var createInstance = lambda.Compile();
return reader => new DefaultConstructorHelper(
createInstance,
caseSensitiveSerializableProperties,
textNodeProperty,
attributeProperties,
reader);
}
var constructorWrappers = validConstructors.Select(c => new ConstructorWrapper(c)).ToArray();
return reader => new NonDefaultConstructorHelper(
constructorWrappers,
serializableProperties,
textNodeProperty,
attributeProperties,
caseSensitiveSerializableProperties,
reader);
}
示例14: DownloadWithProgress
public static void DownloadWithProgress(ICollection<DownloadTarget> downloadTargets, IUser user = null)
{
new NetAsyncDownloader(user ?? new NullUser())
{
onCompleted = (urls, filenames, errors) =>
{
if (filenames == null || urls == null) return;
for (var i = 0; i < Math.Min(urls.Length, filenames.Length); i++)
{
File.Move(filenames[i], downloadTargets.First(p => p.uri == urls[i]).filename);
}
}
}.DownloadAndWait(downloadTargets.ToDictionary(p => p.uri, p => p.size));
}
示例15: DeserializeSetting
private object DeserializeSetting(ICollection<Setting> values, bool isItemized, Type settingType)
{
var convert = new Func<object, Type, object>((obj, type) =>
{
if (obj.GetType() == type)
{
return obj;
}
var result = Converter.Convert(obj, type, CultureInfo.InvariantCulture);
return result;
});
if (isItemized)
{
var data = (object)null;
if (settingType.IsArray)
{
data = values.Select(x => x.Value);
}
if (settingType.IsList())
{
data = values.Select(x => x.Value);
}
if (settingType.IsHashSet())
{
data = values.Select(x => x.Value);
}
if (settingType.IsDictionary())
{
data = values.ToDictionary(x => x.Name.Key, x => x.Value);
}
return convert(data, settingType);
}
else
{
return convert(values.Single().Value, settingType);
}
}