本文整理汇总了C#中IDictionary.Select方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.Select方法的具体用法?C# IDictionary.Select怎么用?C# IDictionary.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RetailAndPowerTrend
public ActionResult RetailAndPowerTrend(IDictionary<string, GraphModel> graphModels)
{
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var months = graphModels.Select(x => x.Key.Substring(0, 3));
ViewBag.months = serializer.Serialize(months);
var actualManpowers = graphModels.Select(x => x.Value.ActualManPower);
ViewBag.actualManPowers = serializer.Serialize(actualManpowers);
var retails = graphModels.Select(x => x.Value.Retail);
ViewBag.retails = serializer.Serialize(retails);
var planManpower = graphModels.Select(x => x.Value.PlanManPower);
ViewBag.planManPower = serializer.Serialize(planManpower);
return PartialView();
}
示例2: SchemaManager
static SchemaManager()
{
const short arraySize = 3;
CsdlNamespaces = new Dictionary<Version, XNamespace>(arraySize);
CsdlNamespaces.Add(EntityFrameworkVersion.Version1, XNamespace.Get("http://schemas.microsoft.com/ado/2006/04/edm"));
CsdlNamespaces.Add(EntityFrameworkVersion.Version2, XNamespace.Get("http://schemas.microsoft.com/ado/2008/09/edm"));
CsdlNamespaces.Add(EntityFrameworkVersion.Version3, XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/edm"));
CsdlNamespaceNames = CsdlNamespaces.Select(n => n.Value.NamespaceName).ToArray();
MslNamespaces = new Dictionary<Version, XNamespace>(arraySize);
MslNamespaces.Add(EntityFrameworkVersion.Version1, XNamespace.Get("urn:schemas-microsoft-com:windows:storage:mapping:CS"));
MslNamespaces.Add(EntityFrameworkVersion.Version2, XNamespace.Get("http://schemas.microsoft.com/ado/2008/09/mapping/cs"));
MslNamespaces.Add(EntityFrameworkVersion.Version3, XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/mapping/cs"));
MslNamespaceNames = MslNamespaces.Select(n => n.Value.NamespaceName).ToArray();
SsdlNamespaces = new Dictionary<Version, XNamespace>(arraySize);
SsdlNamespaces.Add(EntityFrameworkVersion.Version1, XNamespace.Get("http://schemas.microsoft.com/ado/2006/04/edm/ssdl"));
SsdlNamespaces.Add(EntityFrameworkVersion.Version2, XNamespace.Get("http://schemas.microsoft.com/ado/2009/02/edm/ssdl"));
SsdlNamespaces.Add(EntityFrameworkVersion.Version3, XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/edm/ssdl"));
SsdlNamespaceNames = SsdlNamespaces.Select(n => n.Value.NamespaceName).ToArray();
EdmxNamespaces = new Dictionary<Version, XNamespace>(arraySize);
EdmxNamespaces.Add(EntityFrameworkVersion.Version1, XNamespace.Get("http://schemas.microsoft.com/ado/2007/06/edmx"));
EdmxNamespaces.Add(EntityFrameworkVersion.Version2, XNamespace.Get("http://schemas.microsoft.com/ado/2008/10/edmx"));
EdmxNamespaces.Add(EntityFrameworkVersion.Version3, XNamespace.Get("http://schemas.microsoft.com/ado/2009/11/edmx"));
EdmxNamespaceNames = EdmxNamespaces.Select(n => n.Value.NamespaceName).ToArray();
NamespaceToVersionReverseLookUp = new Dictionary<XNamespace, Version>();
foreach (var kvp in CsdlNamespaces.Concat(MslNamespaces).Concat(SsdlNamespaces).Concat(EdmxNamespaces))
{
NamespaceToVersionReverseLookUp.Add(kvp.Value, kvp.Key);
}
}
示例3: Query
/// <summary>
/// <para>Modifies target URL address by adding by adding given list of name/value pairs to its Query component.</para>
/// <para>Names and values of query string parameters are URL-encoded.</para>
/// </summary>
/// <param name="self">URI address to be modified.</param>
/// <param name="parameters">Map of name/value parameters for query string.</param>
/// <returns>Updated URI address.</returns>
/// <exception cref="ArgumentNullException">If either <paramref name="self"/> or <paramref name="parameters"/> is a <c>null</c> reference.</exception>
/// <seealso cref="Query(Uri, object)"/>
/// <seealso cref="Query(Uri, IDictionary{string, object})"/>
public static Uri Query(this Uri self, IDictionary<string, string> parameters)
{
var builder = new UriBuilder(self);
var query = parameters.Select(parameter => $"{parameter.Key.UrlEncode()}={parameter.Value.UrlEncode()}").Join("&");
builder.Query = builder.Query.Length > 1 ? builder.Query.Substring(1) + (query.IsEmpty() ? string.Empty : "&" + query) : query;
return builder.Uri;
}
示例4: CreateSign
public static string CreateSign(IDictionary<string, string> parameters, string key, string charset)
{
string[] array = parameters.Select(item => string.Format("{0}={1}", item.Key, item.Value)).ToArray();
string originalstr = string.Concat(string.Join("&", array), key);
return CryptoUtil.MD5(originalstr, charset);
}
示例5: CreateQueryString
private static string CreateQueryString(
IDictionary<string, string> clientFilters,
int page)
{
// Go through, replacing the page.number query param's value with
// the actual page. Preserves other query parameters, since they're
// still needed to provide the correct pagination links.
var queries = clientFilters.Select(kv =>
{
var key = kv.Key;
var value = kv.Key == Constants.QueryNames.PageNumber ? page.ToString() : kv.Value;
if (string.IsNullOrEmpty(value))
{
return null;
}
if (!key.Contains("."))
{
return new { Key = key, Value = value };
}
var left = key.Substring(0, key.IndexOf(".", StringComparison.InvariantCulture));
var right = key.Substring(left.Length + 1);
return new { Key = left + $"[{right}]", Value = value };
}).Where(k => k != null).ToList();
return queries.Any()
? "?" + string.Join("&", queries.Select(kv => $"{kv.Key}={kv.Value}"))
: null;
}
示例6: FormUrlEncode
static string FormUrlEncode(IDictionary<string, string> data)
{
var pairs = data.Select(pair => string.Format("{0}={1}",
WebUtility.UrlEncode(pair.Key),
WebUtility.UrlEncode(pair.Value)));
return string.Join("&", pairs);
}
示例7: CompileDocumentType
public static Type CompileDocumentType(Type baseType, IDictionary<string, Type> fields)
{
string signature = baseType.FullName + string.Join(";", fields.Select(f => f.ToString()));
Type type = null;
lock (_cachedTypes)
{
if (_cachedTypes.ContainsKey(signature))
{
type = _cachedTypes[signature];
}
}
if (type == null)
{
type = CompileDocumentTypeInternal(baseType, fields);
lock (_cachedTypes)
{
if (!_cachedTypes.ContainsKey(signature))
{
_cachedTypes.Add(signature, type);
}
}
}
return type;
}
示例8: GetBdmtTitles
private static string GetBdmtTitles(IDictionary<Language, string> bdmtTitles)
{
return !bdmtTitles.Any()
? null
: string.Join(Environment.NewLine,
bdmtTitles.Select(pair => string.Format("{0}: {1}", pair.Key.ISO_639_2, pair.Value)));
}
示例9: ToQueryString
public static string ToQueryString(IDictionary<string, string> pairs)
{
// http://stackoverflow.com/questions/829080/how-to-build-a-query-string-for-a-url-in-c/829138#829138
return string.Join("&", pairs.Select(
(pair) => string.Format("{0}={1}", UrlEncode(pair.Key), UrlEncode(pair.Value))
));
}
示例10: Remap
public void Remap(IDictionary<string, AppFunc> map)
{
_map = map
.Select(kv => Tuple.Create(kv.Key, kv.Value))
.OrderByDescending(m => m.Item1.Length)
.ToArray();
}
示例11: GetCompilation
public CSharpCompilation GetCompilation(string assemblyName, IDictionary<string, string> files, out SyntaxTree[] trees)
{
var options = new CSharpParseOptions(_languageVersion);
trees = files.Select(x =>
{
var text = x.Value;
var tree = CSharpSyntaxTree.ParseText(text, options: options);
if (tree.GetDiagnostics().Any())
throw new Exception(string.Format("Syntax error in file \"{0}\".", x.Key));
return tree;
}).ToArray();
// adding everything is going to cause issues with dynamic assemblies
// so we would want to filter them anyway... but we don't need them really
//var refs = AssemblyUtility.GetAllReferencedAssemblyLocations().Select(x => new MetadataFileReference(x));
// though that one is not ok either since we want our own reference
//var refs = Enumerable.Empty<MetadataReference>();
// so use the bare minimum
var asms = ReferencedAssemblies;
var a1 = typeof(Builder).Assembly;
asms.Add(a1);
foreach (var a in GetDeepReferencedAssemblies(a1)) asms.Add(a);
var refs = asms.Select(x => MetadataReference.CreateFromFile(x.Location));
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
var compilation = CSharpCompilation.Create(
assemblyName,
/*syntaxTrees:*/ trees,
/*references:*/ refs,
compilationOptions);
return compilation;
}
示例12: TestStrings
private void TestStrings(
IEnumerable<string> testData,
IDictionary<string, string> testQueries,
Func<string, Expression<Func<TestDatabaseExtensions.Simple, bool>>> filterExpressionForTest)
{
TestStrings(testData, testQueries.Select(test => Tuple.Create(test.Key, test.Value)).ToList(), filterExpressionForTest);
}
示例13: UncompressedMemoryArchive
/// <summary>
/// Constructor.
/// </summary>
public UncompressedMemoryArchive(IDictionary<string, byte[]> files)
{
_contents = files
.Select(kvp => new UncompressedMemoryArchiveFile(kvp.Key, kvp.Value))
.Cast<IArchiveFile>()
.ToList();
}
示例14: Convert
/// <summary>
/// Converts the specified parameters.
/// </summary>
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
public static NameValuePairList Convert(IDictionary<string, string> parameters)
{
return new NameValuePairList {
Count = (uint)parameters.Count,
Pairs = parameters.Select(p => new NameValuePair(p.Key, p.Value)).ToArray()
};
}
示例15: CreateQueryString
private static string CreateQueryString(
IDictionary<string, string> clientFilters,
int page)
{
// Go through, replacing the page.number query param's value with
// the actual page. Preserves other query parameters, since they're
// still needed to provide the correct pagination links.
var queries = clientFilters.Select(kv =>
{
var key = kv.Key;
var value = kv.Key == Constants.PageNumberQueryName ? page.ToString() : kv.Value;
if (string.IsNullOrEmpty(value))
{
return null;
}
var parserMatch = queryParser.Match(key);
if (!parserMatch.Success)
{
return new { Key = key, Value = value };
}
var left = parserMatch.Groups["left"].Value;
var right = parserMatch.Groups["right"].Value;
return new { Key = left + $"[{right}]", Value = value };
}).Where(k => k != null).ToList();
return queries.Any()
? "?" + string.Join("&", queries.Select(kv => $"{kv.Key}={kv.Value}"))
: null;
}