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


C# IDictionary.Count方法代码示例

本文整理汇总了C#中IDictionary.Count方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.Count方法的具体用法?C# IDictionary.Count怎么用?C# IDictionary.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDictionary的用法示例。


在下文中一共展示了IDictionary.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

    // TODO: If you ever figure out how to find the end of a BitStream, remove the count header from this.
    public static void Serialize(this BitStream @this, IDictionary<string, PlayerSnapshot> value)
    {
        if (@this.isWriting)
        {
            // Write count to stream first
            int count = value.Count();
            @this.Serialize(ref count);

            // Then write all deltas
            foreach (var item in value)
            {
                string guid = item.Key;
                @this.Serialize(ref guid);
                @this.Serialize(item.Value);
            }
        }
        else
        {
            // Read count from stream first
            int count = 0;
            @this.Serialize(ref count);

            // Then read all deltas
            for (int i = 0; i < count; i++)
            {
                string guid = null;
                @this.Serialize(ref guid);

                PlayerSnapshot snapshot = new PlayerSnapshot();
                @this.Serialize(snapshot);

                value.Add(guid, snapshot);
            }
        }
    }
开发者ID:nbilling,项目名称:TNPRH,代码行数:36,代码来源:BitSteamExtensions.cs

示例2: VerifyPropertyCollection

        private static void VerifyPropertyCollection(IDictionary<string, object> properties) {
            properties.Count().Should().Be.GreaterThan(0);
            properties.Keys.Contains("Guid").Should().Be.True();
            properties.Keys.Contains("DummyString").Should().Be.True();

            properties.Keys.Contains("Name").Should().Be.True();
            properties["Name"].Should().Be("Widget No1");
        }
开发者ID:debop,项目名称:NFramework,代码行数:8,代码来源:DynamicAccessorToolFixture.cs

示例3: VerifyFieldCollection

        private static void VerifyFieldCollection(IDictionary<string, object> fields) {
            fields.Count().Should().Be.GreaterThan(0);
            fields.Keys.Contains("_guid").Should().Be.True();
            fields.Keys.Contains("_id").Should().Be.True();

            fields.Keys.Contains("_name").Should().Be.True();
            fields["_name"].Should().Be("Widget No1");
        }
开发者ID:debop,项目名称:NFramework,代码行数:8,代码来源:DynamicAccessorToolFixture.cs

示例4: AppendQueryArgs

        public static void AppendQueryArgs(this UriBuilder builder, IDictionary<string, string> args)
        {
            //Requires.NotNull(builder, "builder");

            if (args != null && args.Count() > 0)
            {
                var sb = new StringBuilder(50 + (args.Count() * 10));
                if (!string.IsNullOrEmpty(builder.Query))
                {
                    sb.Append(builder.Query.Substring(1));
                    sb.Append('&');
                }
                sb.Append(CreateQueryString(args));

                builder.Query = sb.ToString();
            }
        }
开发者ID:matthewbga,项目名称:OAuthTestClient,代码行数:17,代码来源:UriBuilderExtensions.cs

示例5: FillRemainingStartingPositions

        private static IDictionary<int, PredictedPlayerScore> FillRemainingStartingPositions(IDictionary<int, PredictedPlayerScore> currentSelectedPlayers, IList<PredictedPlayerScore> playersNotYetSelected)
        {
            if (currentSelectedPlayers.Count() != 5) throw new ArgumentException("Should be 5 mandatory players already selected");
            if (playersNotYetSelected.Count() != 10) throw new ArgumentException("Should be 10 players available to complete team");

            const int PlayerCountRequired = 11 - 1 - GameConstants.MinimumDefendersInStartingTeam -
                                            GameConstants.MinimumForwardsInStartingTeam;

            var playersToSelect = playersNotYetSelected.Where(ps => ps.Player.Position != Position.Goalkeeper).OrderByDescending(ps => ps.PredictedScore).Take(PlayerCountRequired);
            foreach (var player in playersToSelect)
            {
                currentSelectedPlayers.Add(player.Player.Id, player);
            }

            return currentSelectedPlayers;
        }
开发者ID:robinweston,项目名称:fantasyfootballrobot,代码行数:16,代码来源:TeamGameweekSelector.cs

示例6: CreatePostHttpResponse

        public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters,
            int timeout, string userAgent, CookieCollection cookies)
        {
            HttpWebRequest request = null;
            if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
            {
                //对服务端证书进行有效性检验(非第三方权威机构颁发的证书,如自己生成的,不进行验证,这里返回true)
                ServicePointManager.ServerCertificateValidationCallback =
                    new System.Net.Security.RemoteCertificateValidationCallback(CheckValidateionResult);
                request.ProtocolVersion = HttpVersion.Version11;
            }
            request = WebRequest.Create(url) as HttpWebRequest;
            request.UserAgent = userAgent;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Timeout = timeout;

            if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }
            if (!(parameters == null) || parameters.Count() == 0)
            {
                StringBuilder buffer = new StringBuilder();
                bool flag = false;
                foreach (string key in parameters.Keys)
                {
                    if (flag)
                    {
                        buffer.AppendFormat("&{0}={1}", key, parameters[key]);
                    }
                    else
                    {
                        flag = true;
                        buffer.AppendFormat("{0}={1}", key, parameters[key]);
                    }
                }
                byte[] data = Encoding.ASCII.GetBytes(buffer.ToString());
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
            }

            return request.GetResponse() as HttpWebResponse;
        }
开发者ID:the404,项目名称:xyz,代码行数:47,代码来源:HttpHelper.cs

示例7: AppendDictionary

        public void AppendDictionary(OperatorInfo op, bool explode, IDictionary<string, string> dictionary)
        {
            foreach (string key in dictionary.Keys)
            {
                _Result.Append(Encode(key, op.AllowReserved));
                if (explode) _Result.Append('='); else _Result.Append(',');
                AppendValue(dictionary[key], 0, op.AllowReserved);

                if (explode)
                {
                    _Result.Append(op.Seperator);
                }
                else
                {
                    _Result.Append(',');
                }
            }
            if (dictionary.Count() > 0)
            {
                _Result.Remove(_Result.Length - 1, 1);
            }
        }
开发者ID:khalidabuhakmeh,项目名称:Tavis.UriTemplates,代码行数:22,代码来源:Result.cs

示例8: CreateQueryString

        internal static string CreateQueryString(IDictionary<string, string> args)
        {
            //Requires.NotNull(args, "args");

            if (!args.Any())
            {
                return string.Empty;
            }
            var sb = new StringBuilder(args.Count() * 10);

            foreach (var p in args)
            {
                ValidationHelper.VerifyArgument(!string.IsNullOrEmpty(p.Key), "Unexpected Null Or Empty Key");
                ValidationHelper.VerifyArgument(p.Value != null, "Unexpected Null Value", p.Key);
                sb.Append(EscapeUriDataStringRfc3986(p.Key));
                sb.Append('=');
                sb.Append(EscapeUriDataStringRfc3986(p.Value));
                sb.Append('&');
            }
            sb.Length--; // remove trailing &

            return sb.ToString();
        }
开发者ID:matthewbga,项目名称:OAuthTestClient,代码行数:23,代码来源:UriBuilderExtensions.cs

示例9: AssertCreation

 private void AssertCreation(IDictionary<string, string> dict)
 {
     Assert.AreEqual(2, dict.Count());
      var actual = dict
                 .Where(x => x.Key.EndsWith("Customer2.g.cs"))
                 .First()
                 .Value ;
      actual = StringUtilities.RemoveFileHeaderComments(actual);
      Assert.AreEqual(expected1, actual);
      actual = dict
                 .Where(x => x.Key.EndsWith("Customer.g.cs"))
                 .First()
                 .Value;
      actual = StringUtilities.RemoveFileHeaderComments(actual);
      Assert.AreEqual(expected2, actual);
 }
开发者ID:KathleenDollard,项目名称:CodeFirstMetadata,代码行数:16,代码来源:DomainGenerationTests.cs

示例10: CloneStringParameters

 private static void CloneStringParameters(string sourceName, string targetName, IDictionary<string, object> parameters)
 {
     List<string> keys = parameters.Keys.ToList();
     for (int idx = 0; idx < parameters.Count(); idx++)
     {
         if (parameters[keys[idx]] is string)
         {
             if ((parameters[keys[idx]] as string).Contains(sourceName))
             {
                 parameters[keys[idx]] = (parameters[keys[idx]] as string).Replace(sourceName, targetName);
             }
         }
     }
 }
开发者ID:caveman-dick,项目名称:BuildManager,代码行数:14,代码来源:TfsClientRepository.cs

示例11: GetChannels

        private async Task GetChannels()
        {
            var client = new HttpClient
            {
                BaseAddress = new Uri(string.Format("https://{0}.slack.com", _team)),

            };
            var response = await
                client.GetAsync(new Uri(string.Format("api/channels.list?token={0}&pretty=1",
                    _userToken), UriKind.Relative));

            var content = await response.Content.ReadAsStringAsync();
            var json = JToken.Parse(content);
            if (!json["ok"].Value<bool>())
            {
                Logger.Warn("Could not fetch list of channels. You may find issues with mmbot not speaking in channels until messages have been posted there.");
                return;
            }
            
            _channelMapping = json["channels"].ToDictionary(c => c["name"].ToString(), c => c["id"].ToString());

            Logger.Info(string.Format("Discovered {0} Slack rooms", _channelMapping.Count()));
        }
开发者ID:jvanzella,项目名称:mmbot,代码行数:23,代码来源:SlackAdapter.cs

示例12: InvokeKvpOperation

        protected void InvokeKvpOperation(IDictionary<String, Object> args, IDictionary<String, Object> data, String operationName)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (data.Count() == 0)
            {
                return;
            }

            var kvpItems = ToKvpItems(data);
            using (var vmMgmt = WMIHelper.GetFirstInstance(WMI_Namespace, WMI_Class_Msvm_VirtualSystemManagementService))
            using (var vm = WMIHelper.QueryFirstInstacne(WMI_Namespace, WMI_Class_Msvm_ComputerSystem, String.Format("Name='{0}'", args["VirtualMachineName"])))
            {
                if(batchMode)
                {
                    InvokeKvpOperation(vmMgmt, vm, operationName, kvpItems);
                }
                else
                {
                    foreach (var kvpItem in kvpItems)
                    {
                        InvokeKvpOperation(vmMgmt, vm, operationName, new String[] { kvpItem });
                    }
                }

            }
        }
开发者ID:biapar,项目名称:enhanced-monitoring-service,代码行数:35,代码来源:KeyValuePairWriter.cs

示例13: CheckFields

 private void CheckFields(IDictionary<string, string> expected, IDictionary<string, string> actual)
 {
     foreach (var field in expected)
     {
         if (field.Value != null)
         {
             Assert.IsTrue(actual.ContainsKey(field.Key), string.Format("Record is not complete. Missing field \"{0}\".", field.Key));
             Assert.AreEqual(field.Value, actual[field.Key], string.Format("Wrong value for field \"{0}\".", field.Key));
         }
         else
         {
             Assert.IsFalse(actual.ContainsKey(field.Key), string.Format("Unexpected field \"{0}\" (value: \"{1}\").", field.Key, field.Value));
         }
     }
     Assert.AreEqual(expected.Count(f => f.Value != null), actual.Count, "Unexpected count of fields.");
 }
开发者ID:klapantius,项目名称:lit,代码行数:16,代码来源:Parser.cs

示例14: delete

        public void delete( DatabaseToken token, string table, IDictionary<string, object> constraints )
        {
            // Are there any binary columns in this table? If so, we need to pay attention
            // to eliminating the files from the file system too.
            IEnumerable<string> binaryCols = findBinaryColumns( table );
            if( binaryCols.Any() )
            {
            // Find the row we're going to delete.
            var results = selectRaw( MySqlToken.Crack( token ), table, constraints );
            if( !results.Any() )
                return;

            deleteBinaryColumns( table, binaryCols, results );
            }

            string sql =  CultureFree.Format( "delete from {0}", table );
            if( constraints.Count() > 0 )
            sql += makeWhereClause( constraints );

            // Add in the updated values, plus the ID for the where clause.
            MySqlCommand cmd = new MySqlCommand( sql, MySqlToken.Crack( token ) );
            insertQueryParameters( cmd, table, constraints );

            // Do the delete.
            cmd.ExecuteNonQuery();
        }
开发者ID:kayateia,项目名称:climoo,代码行数:26,代码来源:MySqlDatabase.cs

示例15: RandomlyChange

 public static void RandomlyChange(float percentageOfSituations, IDictionary<Situation, RobotAction> strategy)
 {
     int itemsToChange = (int) (strategy.Count()*percentageOfSituations/100.0);
     for (int i = 0; i < itemsToChange; i++)
     {
         Situation situationToRandonlyChange = GetRandomSituation();
         RobotAction action = GetRandomAction();
         strategy[situationToRandonlyChange] = action;
     }
 }
开发者ID:hombredequeso,项目名称:Robbie-Robot,代码行数:10,代码来源:StrategyGenerator.cs


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