本文整理汇总了C#中IDictionary.Where方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.Where方法的具体用法?C# IDictionary.Where怎么用?C# IDictionary.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToXml
public static string ToXml(IDictionary<string, object> dictionary, string elementName)
{
string attributes = dictionary.Where(kvp => kvp.Key.EndsWith(AttributeMarker)).Aggregate<KeyValuePair<string, object>, string>(null, (current, kvp) => current + string.Format(" {0}=\"{1}\"", kvp.Key.Replace(AttributeMarker, string.Empty), kvp.Value));
var stringBuilder = new StringBuilder("<{0}{1}>".Fmt(elementName, attributes));
foreach (var kvp in dictionary.Where(k => !k.Key.EndsWith(AttributeMarker)))
{
if (kvp.Value is IDictionary<string, object>)
stringBuilder.Append(ToXml((IDictionary<string, object>)kvp.Value, kvp.Key));
else if (kvp.Value is dynamic[])
{
foreach (var dyn in (dynamic[])kvp.Value)
{
stringBuilder.Append(ToXml(dyn, kvp.Key));
}
}
else if (kvp.Value.GetType().IsArray || (kvp.Value.GetType().IsGenericType && kvp.Value is IEnumerable))
{
foreach (var value in (IEnumerable)kvp.Value)
{
stringBuilder.Append("<{0}>{1}</{0}>".Fmt(kvp.Key, value));
}
}
else
stringBuilder.Append("<{0}>{1}</{0}>".Fmt(kvp.Key, kvp.Value));
}
stringBuilder.Append("</{0}>".Fmt(elementName));
return stringBuilder.ToString();
}
示例2: Reassemble
public IDictionary<string, string> Reassemble(string clientId, IDictionary<string, string> input)
{
var expectedDatabusProperties = input.Where(kv => kv.Key.Contains("NServiceBus.DataBus.")).ToList();
if (!expectedDatabusProperties.Any())
{
return input;
}
lock (headers)
{
IDictionary<string, string> collection;
if (!headers.TryGetValue(clientId, out collection))
{
var message = string.Format("Expected {0} databus properties. None were received. Please resubmit.",expectedDatabusProperties.Count);
throw new ChannelException(412,message);
}
foreach (var propertyHeader in expectedDatabusProperties)
{
string propertyValue;
if (!collection.TryGetValue(propertyHeader.Key, out propertyValue))
{
var message = string.Format("Databus property {0} was never received. Please resubmit.",propertyHeader.Key);
throw new ChannelException(412,message);
}
input[propertyHeader.Key] = propertyValue;
}
headers.Remove(clientId);
}
return input;
}
示例3: Store
/// <summary>
/// Сохраняет заголовки входящего сообщения.
/// </summary>
/// <param name="headers">Заголовки входящего сообщения.</param>
public void Store(IDictionary<string, object> headers)
{
var refindedHeaders = headers
.Where(p => !this.blackHeaderSet.Contains(p.Key))
.ToDictionary(p => p.Key, p => p.Value);
CallContext.LogicalSetData(this.storageKey, refindedHeaders);
}
示例4: Insert
public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction = null,
bool resultRequired = false)
{
var table = adapter.GetSchema().FindTable(tableName);
var insertData = data.Where(p => table.HasColumn(p.Key)).Select((kv, idx) => new InsertColumn
{
Name = kv.Key,
ParameterName = "@p" + idx,
Value = kv.Value,
Column = (FbColumn) table.FindColumn(kv.Key)
}).ToArray();
if (transaction == null)
{
using (var connection = adapter.ConnectionProvider.CreateConnection())
{
connection.Open();
return CreateAndExecuteInsertCommand(connection, table, insertData, resultRequired);
}
}
else
{
return CreateAndExecuteInsertCommand(transaction.Connection, table, insertData, resultRequired, transaction);
}
}
示例5: GetFizzBuzzCustomResults
/// <summary>
/// Returns a list of type string representing each number between a given start number an end number, or a particular phrase based on the divisibility of the number value passed.
///
/// </summary>
/// <param name="start">starting number</param>
/// <param name="end">ending number</param>
/// <param name="combos">IDictionary of numbers and associated phrases to replace numbers if any give number is divisible by the passed value.</param>
/// <returns></returns>
public List<string> GetFizzBuzzCustomResults(short start, short end, IDictionary<short,string> combos)
{
if (end < start)
{
throw new ApplicationException("end number must be greater than start number");
}
var results = new List<string>();
var extraLoop = combos != null;
for (var i = start; i <= end; i++)
{
if (!extraLoop) { results.Add(i.ToString()); continue;}
var sb = new StringBuilder();
var i1 = i;
foreach (var combo in combos.Where(combo => i1%combo.Key == 0))
{
sb.Append(combo.Value);
}
results.Add(sb.Length > 0 ? sb.ToString() : i.ToString());
}
return results;
}
示例6: ConvertValue
private static object ConvertValue(string elementName, BsonValue value, IDictionary<string, string> aliases)
{
if (value.IsBsonDocument)
{
aliases = aliases.Where(x => x.Key.StartsWith(elementName + ".")).ToDictionary(x => x.Key.Remove(0, elementName.Length + 1), x => x.Value);
return value.AsBsonDocument.ToSimpleDictionary(aliases);
}
else if (value.IsBsonArray)
return value.AsBsonArray.Select(v => ConvertValue(elementName, v, aliases)).ToList();
else if (value.IsBoolean)
return value.AsBoolean;
else if (value.IsDateTime)
return value.AsDateTime;
else if (value.IsDouble)
return value.AsDouble;
else if (value.IsGuid)
return value.AsGuid;
else if (value.IsInt32)
return value.AsInt32;
else if (value.IsInt64)
return value.AsInt64;
else if (value.IsObjectId)
return value.AsObjectId;
else if (value.IsString)
return value.AsString;
else if (value.BsonType == BsonType.Binary)
return value.AsByteArray;
return value.RawValue;
}
示例7: Upsert
private IDictionary<string, object> Upsert(string tableName, IDictionary<string, object> data, SimpleExpression criteria, bool resultRequired,
IDbConnection connection)
{
var finder = _transaction == null
? new AdoAdapterFinder(_adapter, connection)
: new AdoAdapterFinder(_adapter, _transaction);
var existing = finder.FindOne(tableName, criteria);
if (existing != null)
{
// Don't update columns used as criteria
var keys = criteria.GetOperandsOfType<ObjectReference>().Select(o => o.GetName().Homogenize());
var updateData = data.Where(kvp => keys.All(k => k != kvp.Key.Homogenize())).ToDictionary();
if (updateData.Count == 0)
{
return existing;
}
var commandBuilder = new UpdateHelper(_adapter.GetSchema()).GetUpdateCommand(tableName, updateData, criteria);
if (_transaction == null)
{
_adapter.Execute(commandBuilder, connection);
}
else
{
_adapter.Execute(commandBuilder, _transaction);
}
return resultRequired ? finder.FindOne(tableName, criteria) : null;
}
var inserter = _transaction == null
? new AdoAdapterInserter(_adapter, connection)
: new AdoAdapterInserter(_adapter, _transaction);
return inserter.Insert(tableName, data, resultRequired);
}
示例8: ExploreProjects
public void ExploreProjects(IDictionary<IProject, FileSystemPath> projects, MetadataLoader loader, IUnitTestElementsObserver observer)
{
var silverlightProjects = projects.Where(p => p.Key.IsSilverlight()).ToDictionary(p => p.Key, p => p.Value);
this.metadataElementsSource.ExploreProjects(silverlightProjects, loader, observer, this.ExploreAssembly);
observer.OnCompleted();
}
示例9: Insert
public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction, bool resultRequired = false)
{
var table = DatabaseSchema.Get(adapter.ConnectionProvider, adapter.ProviderHelper).FindTable(tableName);
if (table == null) throw new SimpleDataException(String.Format("Table '{0}' not found", tableName));
var insertData = data.Where(p => table.HasColumn(p.Key) && !table.FindColumn(p.Key).IsIdentity).ToDictionary();
var insertColumns = insertData.Keys.Select(table.FindColumn).ToArray();
var columnsSql = insertColumns.Select(s => s.QuotedName).Aggregate((agg, next) => String.Concat(agg, ",", next));
var valuesSql = insertColumns.Select((val, idx) => ":p" + idx.ToString()).Aggregate((agg, next) => String.Concat(agg, ",", next));
var insertSql = string.Format("INSERT INTO {0} ({1}) VALUES({2}) RETURNING *;", table.QualifiedName, columnsSql, valuesSql);
if (transaction != null)
{
using(var cmd = transaction.Connection.CreateCommand())
{
cmd.Transaction = transaction;
cmd.CommandText = insertSql;
return ExecuteInsert(cmd, insertColumns, insertData.Values.ToArray());
}
}
using (var conn = adapter.ConnectionProvider.CreateConnection())
{
conn.Open();
using(var cmd = conn.CreateCommand())
{
cmd.CommandText = insertSql;
return ExecuteInsert(cmd, insertColumns, insertData.Values.ToArray());
}
}
}
示例10: CommandProvider
public CommandProvider(CommandConfigurer commandConfigurer)
{
_commands = new Dictionary<string, StackCommand>();
_constants = new Dictionary<String, double>();
commandConfigurer.config(this);
_operators = _commands.Where(entry => entry.Value is Operator).Select(entry => entry.Key).ToList();
}
示例11: ClaimsFromJwt
private static ICollection<Claim> ClaimsFromJwt(IDictionary<string, object> jwtData, string issuer)
{
issuer = issuer ?? DefaultIssuer;
var list = jwtData.Where(p => !claimsToExclude.Contains(p.Key)) // don't include specific claims
.Select(p => new { Key = p.Key, Values = p.Value as JArray ?? new JArray { p.Value } }) // p.Value is either claim value of ArrayList of values
.SelectMany(p => p.Values.Cast<object>()
.Select(v => new Claim(p.Key, v.ToString(), StringClaimValueType, issuer, issuer)))
.ToList();
// set claim for user name
// use original jwtData because claimsToExclude filter has sub and otherwise it wouldn't be used
var userNameClaimType = claimTypesForUserName.FirstOrDefault(ct => jwtData.ContainsKey(ct));
if (userNameClaimType != null)
{
list.Add(new Claim(NameClaimType, jwtData[userNameClaimType].ToString(), StringClaimValueType, issuer, issuer));
}
// set claims for roles array
list.Where(c => c.Type == "roles").ToList().ForEach(r =>
{
list.Add(new Claim(RoleClaimType, r.Value, StringClaimValueType, issuer, issuer));
});
list.RemoveAll(c => c.Type == "roles");
return list;
}
示例12: SerializeElements
void SerializeElements(IDictionary<string, CfgMetadata> meta, object node, StringBuilder builder, int level) {
foreach (var pair in meta.Where(kv => kv.Value.ListType != null)) {
var items = (IList)meta[pair.Key].Getter(node);
if (items == null || items.Count == 0)
continue;
Indent(builder, level);
builder.Append("<");
builder.Append(pair.Key);
builder.AppendLine(">");
foreach (var item in items) {
var metaData = CfgMetadataCache.GetMetadata(item.GetType());
Indent(builder, level + 1);
builder.Append("<add");
SerializeAttributes(metaData, item, builder);
if(JustAttributes(metaData, item)) {
builder.AppendLine(" />");
} else {
builder.AppendLine(">");
SerializeElements(metaData, item, builder, level + 2);
Indent(builder, level + 1);
builder.AppendLine("</add>");
}
}
Indent(builder, level);
builder.Append("</");
builder.Append(pair.Key);
builder.AppendLine(">");
}
}
示例13: Reassemble
public IDictionary<string, string> Reassemble(string clientId, IDictionary<string, string> input)
{
var expectedDatabusProperties =
input.Where(kv => kv.Key.Contains(HeaderMapper.DATABUS_PREFIX)).ToList();
if (!expectedDatabusProperties.Any())
{
return input;
}
lock (headers)
{
IDictionary<string, string> collection;
if (!headers.TryGetValue(clientId, out collection))
{
throw new ChannelException(412,
string.Format("Expected {0} databus properties. None were received. Please resubmit.",
expectedDatabusProperties.Count));
}
foreach (var propertyHeader in expectedDatabusProperties)
{
if (!collection.ContainsKey(propertyHeader.Key))
{
throw new ChannelException(412,
string.Format("Databus property {0} was never received. Please resubmit.",
propertyHeader.Key));
}
input[propertyHeader.Key] = collection[propertyHeader.Key];
}
headers.Remove(clientId);
}
return input;
}
示例14: DictToQuerystring
public static string DictToQuerystring(IDictionary<string, string> qs)
{
return string.Join("&", qs
.Where(k => !string.IsNullOrEmpty(k.Key))
.Select(k => string.Format("{0}={1}", HttpUtility.UrlEncode(k.Key), HttpUtility.UrlEncode(k.Value)))
.ToArray());
}
示例15: GetAttributes
private string GetAttributes(IDictionary<string, object> htmlAttributes, ISet<string> skippedAttributes)
{
var attributes = String.Join(" ", htmlAttributes
.Where(kvp => !skippedAttributes.Contains(kvp.Key))
.Select(kvp => kvp.Key + "=\"" + kvp.Value + "\""));
return attributes != "" ? (" " + attributes) : "";
}