当前位置: 首页>>代码示例>>C#>>正文


C# ICollection.ToDictionary方法代码示例

本文整理汇总了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);
 }
开发者ID:raimu,项目名称:kephas,代码行数:7,代码来源:Calculator.cs

示例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>();
        }
开发者ID:Lavrinovich13,项目名称:EPAM-ATSEmulator,代码行数:11,代码来源:ATS.cs

示例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);
     }
 }
开发者ID:hazzik,项目名称:ReSharper.XUnitTestRunner,代码行数:12,代码来源:ReSharperRunnerLogger.cs

示例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);
        }
开发者ID:0x49D1,项目名称:WinPass,代码行数:13,代码来源:Entry.cs

示例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;
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:42,代码来源:Program.cs

示例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("}");
        }
开发者ID:aaubry,项目名称:FluentOMatic,代码行数:21,代码来源:Program.cs

示例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);
                });
        }
开发者ID:luke-pearson,项目名称:foobox,代码行数:42,代码来源:SyncEngine.cs

示例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();
            }
        }
开发者ID:luke-pearson,项目名称:foobox,代码行数:24,代码来源:SyncEngine.cs

示例9: CellsToRow

 public Dictionary<string, ICell> CellsToRow(ICollection<ICell> cells)
 {
     return cells.ToDictionary(
             cell => Headers[cell.ColumnNum - 1],
             cell => cell);
 }
开发者ID:epam,项目名称:JDI,代码行数:6,代码来源:Rows.cs

示例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;
        }
开发者ID:Kingston-Wharves,项目名称:TestProjects,代码行数:67,代码来源:Validation.BusinessManager.cs

示例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));
        }
开发者ID:paultyng,项目名称:GoogleVisualization,代码行数:11,代码来源:Query.cs

示例12: _convertTypes

 protected Dictionary<string, SqlColumnType> _convertTypes(ICollection<Dictionary<string, object>> sysobjectsInfos)
 {
     return sysobjectsInfos.ToDictionary(
         row => row["COLUMN_NAME"].ToString(),
         row => _determineType(row));
 }
开发者ID:kd7iwp,项目名称:Lasy,代码行数:6,代码来源:SQLAnalyzer.cs

示例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);
            }
开发者ID:JonOsment,项目名称:XSerializer,代码行数:66,代码来源:CustomSerializer.cs

示例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));
 }
开发者ID:Zor-X-L,项目名称:CKAN,代码行数:14,代码来源:Net.cs

示例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);
            }
        }
开发者ID:he-dev,项目名称:SmartConfig,代码行数:43,代码来源:SettingDeserializer.cs


注:本文中的ICollection.ToDictionary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。