本文整理汇总了C#中IDictionary.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.GetEnumerator方法的具体用法?C# IDictionary.GetEnumerator怎么用?C# IDictionary.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildQuery
public static string BuildQuery(IDictionary<string, string> parameters)
{
StringBuilder builder = new StringBuilder();
bool flag = false;
IEnumerator<KeyValuePair<string, string>> enumerator = parameters.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<string, string> current = enumerator.Current;
string key = current.Key;
KeyValuePair<string, string> pair2 = enumerator.Current;
string str2 = pair2.Value;
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(str2))
{
if (flag)
{
builder.Append("&");
}
builder.Append(key);
builder.Append("=");
builder.Append(HttpUtility.UrlEncode(str2, Encoding.UTF8));
flag = true;
}
}
return builder.ToString();
}
示例2: PopulateValues
private void PopulateValues(IDictionary from, System.Collections.Generic.List<KeyValue> to)
{
IDictionaryEnumerator ide = from.GetEnumerator();
ValueWithType valueWithType = null;
KeyValue keyValue = null;
while (ide.MoveNext())
{
keyValue = new KeyValue();
keyValue.key = ide.Key.ToString();
if (ide.Value is ArrayList)
{
ArrayList list = (ArrayList)ide.Value;
foreach (object value in list)
{
valueWithType = new ValueWithType();
valueWithType.value = GetValueString(value);
valueWithType.type = value.GetType().FullName;
keyValue.value.Add(valueWithType);
}
}
else
{
valueWithType = new ValueWithType();
valueWithType.value = GetValueString(ide.Value);
valueWithType.type = ide.Value.GetType().FullName;
keyValue.value.Add(valueWithType);
}
to.Add(keyValue);
}
}
示例3: BuildPostData
/// <summary>
/// 组装普通文本请求参数。
/// </summary>
/// <param name="parameters">Key-Value形式请求参数字典。</param>
/// <returns>URL编码后的请求数据。</returns>
private static string BuildPostData(IDictionary<string, string> parameters)
{
StringBuilder postData = new StringBuilder();
bool hasParam = false;
IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator();
while (dem.MoveNext())
{
string name = dem.Current.Key;
string value = dem.Current.Value;
// 忽略参数名或参数值为空的参数
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
{
if (hasParam)
{
postData.Append("&");
}
postData.Append(name);
postData.Append("=");
postData.Append(Uri.EscapeUriString(value));
hasParam = true;
}
}
return postData.ToString();
}
示例4: DoPost
public string DoPost(string url, IDictionary<string, string> parameters, string input)
{
HttpWebRequest req = GetWebRequest(url, "POST");
req.ContentType = "application/json";
#region build header
IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator();
while (dem.MoveNext())
{
string name = dem.Current.Key;
string value = dem.Current.Value;
// 忽略参数名或参数值为空的参数
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
req.Headers.Add(name, HttpUtility.UrlEncode(value, Encoding.UTF8));
}
#endregion
byte[] postData = Encoding.UTF8.GetBytes(input);
System.IO.Stream reqStream = req.GetRequestStream();
reqStream.Write(postData, 0, postData.Length);
reqStream.Close();
HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
return GetResponseString(rsp, System.Text.Encoding.UTF8);
}
示例5: BuildQuery
/// <summary>
/// 组装普通文本请求参数。
/// </summary>
/// <param name="parameters">Key-Value形式请求参数字典</param>
/// <returns>URL编码后的请求数据</returns>
public static string BuildQuery(IDictionary<string, string> parameters)
{
StringBuilder postData = new StringBuilder();
bool hasParam = false;
IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator();
while (dem.MoveNext())
{
string name = dem.Current.Key;
string value = dem.Current.Value;
// 忽略参数名或参数值为空的参数
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value))
{
if (hasParam)
{
postData.Append("&");
}
postData.Append(name);
postData.Append("=");
postData.Append(HttpUtility.UrlEncode(value, Encoding.UTF8));
hasParam = true;
}
}
return postData.ToString();
}
示例6: OverwriteSequenceNumbers
public static void OverwriteSequenceNumbers(TagLib.Ogg.File file, long position, IDictionary<uint, int> shiftTable)
{
if (file == null)
{
throw new ArgumentNullException("file");
}
if (shiftTable == null)
{
throw new ArgumentNullException("shiftTable");
}
bool flag = true;
IEnumerator<KeyValuePair<uint, int>> enumerator = shiftTable.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
KeyValuePair<uint, int> current = enumerator.Current;
if (current.Value != 0)
{
flag = false;
goto Label_0065;
}
}
}
finally
{
if (enumerator == null)
{
}
enumerator.Dispose();
}
Label_0065:
if (flag)
{
return;
}
while (position < (file.Length - 0x1bL))
{
PageHeader header = new PageHeader(file, position);
int length = (int) (header.Size + header.DataSize);
if (shiftTable.ContainsKey(header.StreamSerialNumber) && (shiftTable[header.StreamSerialNumber] != 0))
{
file.Seek(position);
ByteVector vector = file.ReadBlock(length);
ByteVector data = ByteVector.FromUInt(header.PageSequenceNumber + ((uint) ((long) shiftTable[header.StreamSerialNumber])), false);
for (int i = 0x12; i < 0x16; i++)
{
vector[i] = data[i - 0x12];
}
for (int j = 0x16; j < 0x1a; j++)
{
vector[j] = 0;
}
data.Add(ByteVector.FromUInt(vector.Checksum, false));
file.Seek(position + 0x12L);
file.WriteBlock(data);
}
position += length;
}
}
示例7: Sign
/// <summary>
/// 签名规则:hex(md5(secret+sorted(header_params+url_params+form_params)+body)+secret)
/// </summary>
private static string Sign(IDictionary<string, string> parameters, string body, string secret, string charset)
{
IEnumerator<KeyValuePair<string, string>> em = parameters.GetEnumerator();
// 第1步:把所有参数名和参数值串在一起
StringBuilder query = new StringBuilder(secret);
while (em.MoveNext())
{
string key = em.Current.Key;
if (!TOP_FIELD_SIGN.Equals(key))
{
string value = em.Current.Value;
query.Append(key).Append(value);
}
}
if (body != null)
{
query.Append(body);
}
query.Append(secret);
// 第2步:使用MD5加密
MD5 md5 = MD5.Create();
byte[] bytes = md5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(query.ToString()));
// 第3步:把二进制转化为大写的十六进制
StringBuilder result = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
result.Append(bytes[i].ToString("X2"));
}
return result.ToString();
}
示例8: UpdateExisting
/// <summary>
/// Update any existing rows for the given values, and remove them from the values collection.
/// </summary>
/// <param name="configName"></param>
/// <param name="values"></param>
/// <param name="conn"></param>
/// <param name="transaction"></param>
/// <returns></returns>
public bool UpdateExisting(string configName, IDictionary<long, MonitorRecord<double>> values, IDbConnection conn, IDbTransaction transaction = null)
{
var result = false;
if (values.Count == 0)
return true;
MonitorInfo monitorInfo;
if (_cache.MonitorInfo.TryGetValue(configName, out monitorInfo))
{
var reduceLevel = monitorInfo.FirstReduceLevel;
var reduceMethod = reduceLevel.AggregationClass;
var startTime = values.First().Value.TimeStamp;
var tableName = Support.MakeReducedName(configName, reduceLevel.Resolution);
var updateList = new List<MonitorRecord<double>>();
var combineList = new List<MonitorRecord<double>>();
//Based on the timestamp we have we pull out from the database all recrods that have a date
//grater than the timestamp we have. For each value we find loop through and find the value
//that is the next greatest time past our current value from the database
var existingList = _storageCommands.SelectListForUpdateExisting(tableName, startTime, conn, transaction);
foreach (var existingValue in existingList)
{
var hasNext = false;
var matchingValue = _cache.Empty;
var valuesEnumerator = values.GetEnumerator();
while ((hasNext = valuesEnumerator.MoveNext()) && ((matchingValue = valuesEnumerator.Current.Value).TimeStamp < existingValue.TimeStamp)) ;
combineList.Clear();
if (hasNext && !_cache.Empty.Equals(matchingValue))
{
combineList.Add(existingValue);
combineList.Add(matchingValue);
values.Remove(matchingValue.TimeStamp.Ticks);
}
else
continue;
//Reduce the value we have from the database with the value we have here (thats what is in the combined list)
var update = reduceMethod.Reduce(existingValue.TimeStamp, combineList);
updateList.Add(update);
}
//Update everything in the database
_storageCommands.Update(tableName, updateList, conn, transaction);
result = true;
}
else
throw new DataException("No monitor config found for " + configName);
return result;
}
示例9: WriteElements
private void WriteElements(IWriteContext context, IDictionary map, KeyValueHandlerPair
handlers)
{
IEnumerator elements = map.GetEnumerator();
while (elements.MoveNext())
{
DictionaryEntry entry = (DictionaryEntry)elements.Current;
context.WriteObject(handlers._keyHandler, entry.Key);
context.WriteObject(handlers._valueHandler, entry.Value);
}
}
示例10: AddRange
public virtual void AddRange(IDictionary c)
{
if(c != null)
{
IDictionaryEnumerator e = c.GetEnumerator();
while(e.MoveNext())
{
((IKeyedCollection)this).Add(e.Value, e.Key);
}
}
}
示例11: Hashtable
public Hashtable(IDictionary d, float loadFactor, IEqualityComparer equalityComparer)
: this((d != null) ? d.Count : 0, loadFactor, equalityComparer)
{
if (d == null) {
throw new ArgumentNullException("d", "Dictionary cannot be null.");
}
IDictionaryEnumerator enumerator = d.GetEnumerator();
while (enumerator.MoveNext()) {
this.Add(enumerator.Key, enumerator.Value);
}
}
示例12: AddAll
private static void AddAll(IDictionary<string, string> dest, IDictionary<string, string> from)
{
if (from != null && from.Count > 0)
{
IEnumerator<KeyValuePair<string, string>> em = from.GetEnumerator();
while (em.MoveNext())
{
KeyValuePair<string, string> kvp = em.Current;
dest.Add(kvp.Key, kvp.Value);
}
}
}
示例13: MessageDictionaryEnumerator
public MessageDictionaryEnumerator(MessageDictionary md, IDictionary hashtable)
{
this._md = md;
if (hashtable != null)
{
this._enumHash = hashtable.GetEnumerator();
}
else
{
this._enumHash = null;
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:MessageDictionaryEnumerator.cs
示例14: AddParameters
internal void AddParameters(IDictionary<string, string> parameters)
{
if ((parameters != null) && (parameters.Count > 0))
{
IEnumerator<KeyValuePair<string, string>> enumerator = parameters.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<string, string> current = enumerator.Current;
KeyValuePair<string, string> pair2 = enumerator.Current;
this.AddParameter(current.Key, pair2.Value);
}
}
}
示例15: SerializeDictionary
private void SerializeDictionary(IDictionary value)
{
IDictionaryEnumerator e = value.GetEnumerator();
_writer.BeginObject();
if (e.MoveNext())
{
SerializeKeyValue(e.Key.ToString(), e.Value, true);
}
while (e.MoveNext())
{
SerializeKeyValue(e.Key.ToString(), e.Value, false);
}
_writer.EndObject();
}