本文整理汇总了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);
}
}
}
示例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");
}
示例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");
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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);
}
}
}
}
示例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()));
}
示例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 });
}
}
}
}
示例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.");
}
示例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();
}
示例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;
}
}