本文整理汇总了C#中Dictionary.Concat方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Concat方法的具体用法?C# Dictionary.Concat怎么用?C# Dictionary.Concat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Concat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetArguments
public object[] GetArguments(RouteInvocation route, IRequest request, MethodInfo method)
{
var foundArgs = new Dictionary<string, string[]>(ParameterComparer);
foundArgs.Concat(route.RouteData);
foundArgs.Concat(request.Query);
foundArgs.Concat(request.Form);
var args = new List<object>();
foreach (var parameter in method.GetParameters())
{
object arg = null;
var converter = Converters.FirstOrDefault
(x => x.CanConvert(parameter.ParameterType));
if (converter != null) {
arg = converter.Convert(parameter.ParameterType, parameter.Name, foundArgs);
}
if ((converter == null || arg == null) && parameter.IsOptional)
{
arg = (parameter.HasDefaultValue ? parameter.DefaultValue : null);
}
if (arg != null || parameter.IsOptional)
{
args.Add(arg);
}
else
{
throw new InvalidOperationException(String.Format(
"Required argument {0} was not supplied to method {1} on controller {2}",
parameter.Name, method.Name, method.DeclaringType));
}
}
return args.ToArray();
}
示例2: GetRetroChanges
private static IDictionary<SyntaxNode, SyntaxNode> GetRetroChanges(Compilation compilation, INamedTypeSymbol objectType)
{
var syntaxNodes = new Dictionary<SyntaxNode, SyntaxNode>();
var semanticModels = compilation.SyntaxTrees.Select(x => compilation.GetSemanticModel(x));
var genRefs = FindGenericClassMembers(semanticModels);
//CHANGE
//1. Generic references with cast
//2. Generic T to Object
//======
foreach (var semanticModel in semanticModels)
{
var root = semanticModel.SyntaxTree.GetRoot();
// get cast changes
var castReferences = new Dictionary<SyntaxNode, SyntaxNode>();
CastResursiveMethod(root, semanticModel, genRefs, castReferences);
// get generic T to object
var retroProperties = GenericToObject(root, semanticModel, objectType);
var allChanges = castReferences.Concat(retroProperties);
foreach (var ch in allChanges)
syntaxNodes.Add(ch.Key, ch.Value);
}
return syntaxNodes;
}
示例3: Convert
public Dictionary<string, object> Convert(string propertyName, CustomAttributeData attr)
{
var validations = new Dictionary<string, object>();
var maxLength = GetConstructorArgumentValue(attr, 0);
if (!string.IsNullOrWhiteSpace(maxLength))
{
var maxValidations = SetMaxLengthAAValidation(propertyName, attr, maxLength);
validations = validations.Concat(maxValidations).ToDictionary(x => x.Key, x => x.Value);
}
var minLength = base.GetNamedArgumentValue(propertyName, attr, DataAnnotationConstants.MinimumLength, false);
if (!string.IsNullOrWhiteSpace(minLength))
{
var minValidations = SetMinLengthAAValidation(propertyName, attr, minLength);
validations = validations.Concat(minValidations).ToDictionary(x => x.Key, x => x.Value);
}
return validations;
}
示例4: ReadSubstitionVariablesFromConfigFile
public void ReadSubstitionVariablesFromConfigFile()
{
var configFilePath = ConfigFile;
var result = new Dictionary<string, string>
{
{"SERVERNAME", TargetDatabaseName},
{"CRMDBNAME", CrmDatabaseName}
};
var config =
JsonConvert.DeserializeObject<Config>(File.ReadAllText(configFilePath), new JsonSerializerSettings { });
Variables = result.Concat(config.UsernameReplacements)
.ToDictionary(x => x.Key, x => x.Value);
}
示例5: MergeDictionaries
/// <summary>
/// Merge given dictionaries
/// </summary>
/// <param name="dictionaries">dictionaries to merge</param>
/// <param name="overrideDueplicateWithLatterDictionaryValue">
/// If true and duplicate key exists, then dupe key's values are overriden by latter dictionary values
/// </param>
public Dictionary<string, string> MergeDictionaries(
Dictionary<int, Dictionary<string, string>> dictionaries,
bool overrideDueplicateWithLatterDictionaryValue = true)
{
Dictionary<string, string> result = new Dictionary<string, string>(dictionaries.Count);
var query = overrideDueplicateWithLatterDictionaryValue ? dictionaries.Reverse() : dictionaries;
foreach (var index in query)
{
Dictionary<string, string> d2 = index.Value;
result = result.Concat(d2.Where(x => !result.Keys.Contains(x.Key))).ToDictionary(o => o.Key, o => o.Value);
}
return result;
}
示例6: CreatePostBody
public static FormUrlEncodedContent CreatePostBody(string method, string apikey, string apisig,
IEnumerable<KeyValuePair<string, string>> parameters)
{
var init = new Dictionary<string, string>
{
{"method", method},
{"api_key", apikey},
{"api_sig", apisig},
{"format", ResponseFormat}
};
// TODO ordering
var requestParameters = init.Concat(parameters);
return new FormUrlEncodedContent(requestParameters);
}
示例7: GetSignatureBaseString
private static string GetSignatureBaseString(string httpMethod, string url, Dictionary<string, string> oAuthOptions)
{
var uri = new Uri(url);
var normalizedUrl = string.Format("{0}://{1}{2}", uri.Scheme, uri.Host, uri.AbsolutePath);
var queryString = uri.Query;
var queryParameters = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(queryString))
{
var querySegments = queryString.Split('&');
foreach (string segment in querySegments)
{
var parts = segment.Split('=');
if (parts.Length > 0)
{
var key = parts[0].Trim(new[] { '?', ' ' });
var val = parts[1].Trim();
queryParameters.Add(key, val);
}
}
}
var signableOptionsRaw = oAuthOptions.Concat(queryParameters).OrderBy(k => k.Key);
var signableOptions = new Dictionary<string, string>();
foreach (var option in signableOptionsRaw)
{
var key = UrlEncode(option.Key);
var val = UrlEncode(option.Value);
signableOptions.Add(key,val);
}
IOrderedEnumerable<KeyValuePair<string, string>> orderedSignableOptions = signableOptions.OrderBy(k => k.Key);
var signableOptionParts = orderedSignableOptions.Select(option => String.Format("{0}%3D{1}", option.Key, option.Value)).ToList();
var signableOptionString = string.Join("%26", signableOptionParts);
var signatureParts = new List<string> {httpMethod, UrlEncode(normalizedUrl), signableOptionString};
return string.Join("&", signatureParts);
}
示例8: getAllNodeNamesHelper
private Dictionary<string, CCNode> getAllNodeNamesHelper(Dictionary<string, CCNode> children)
{
Dictionary<string, CCNode> list = new Dictionary<string, CCNode>();
if (children != null)
{
foreach (KeyValuePair<string, CCNode> pair in children)
{
if (!pair.Key.StartsWith("__") && !pair.Key.StartsWith("#"))
{
list.Add(pair.Key, pair.Value);
}
Dictionary<string, CCNode> list2 = getAllNodeNamesHelper(pair.Value.children);
list = list.Concat(list2).ToDictionary(k => k.Key, v => v.Value);
}
}
return list;
}
示例9: PreprocParse
/// <summary>
/// Parses preprocessor instructions.
/// </summary>
public static void PreprocParse(ref lib8081.CPU cpu, ref Dictionary<String, lib8081.instructions.Function> funcs, String code)
{
// Split the string out.
String[] args = util.SplitWithQuotes(code);
switch (args[0])
{
// More ungodly case statements.
case "#load":
PreprocInclude(ref cpu, ref funcs, args);
break;
case "#include":
// No need for a dedicated function.
var Included = PCDParser.GetParsedFunctions(args[1], ref cpu, true);
funcs = funcs.Concat(Included).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
break;
}
}
示例10: Execute
/// <summary>Entry point</summary>
public int Execute(CommandLine cmd, ConfigSource configuration)
{
Initialize(cmd, configuration);
var proc = new Process();
var runtime = configuration.GetRuntime();
var ini = new Dictionary<string, IEnumerable<string>>()
{
{ "magic_quotes_gpc", new string[] { "0" } },
{ "date.timezone", new string[] { TimeZoneInfo.Local.Olson() ?? "UTC" } },
{ "extension", configuration.GetExtensions(runtime) }
};
var use = configuration.GetUse() ?? UseComposer();
Encoding encoding;
Func<string, string> args;
var main = Paths.TryLocate(use, new string[] { Paths.Compose("tools", MainFor(cmd) + ".php") }).FirstOrDefault();
if (null == main)
{
main = Paths.Locate(new string[] { Paths.Binary().DirName() }, new string[] { MainFor(cmd) + "-main.php" }).First();
encoding = Encoding.UTF8;
// Arguments are encoded in utf-7, which is binary-safe
args = Arguments.Encode;
}
else
{
args = Arguments.Escape;
encoding = Encoding.GetEncoding("iso-8859-1");
}
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = configuration.GetExecutable(runtime) ?? "php";
proc.StartInfo.Arguments = string.Format(
"-C -q -d include_path=\".{0}{1}{0}{0}.{0}{2}\" {3} {4} {5}",
Paths.Separator,
string.Join(Paths.Separator, use.Concat(cmd.Options["modules"].Concat(ModulesFor(cmd)))),
string.Join(Paths.Separator, cmd.Options["classpath"].Concat(ClassPathFor(cmd))),
string.Join(" ", IniSettings(ini.Concat(configuration.GetArgs(runtime)))),
main,
string.Join(" ", ArgumentsFor(cmd).Select(args))
);
return cmd.ExecutionModel.Execute(proc, encoding);
}
示例11: GetUsedCarPrice
/// <summary>
/// </summary>
/// <returns></returns>
public string GetUsedCarPrice(Dictionary<string, string> paramList)
{
var paramBase = new Dictionary<string, string>
{
{"key", _appkey},
{"dtype", "json"},
{"method", "getUsedCarPrice"}
};
//合并参数
var parameters = paramBase.Concat(paramList).ToDictionary(k => k.Key, v => v.Value);
var result = DynamicWebService.SendPost(_url, parameters, "get");
var obj = JObject.Parse(result);
var errorCode = obj["reason"].ToString();
return errorCode != "success" ? "0" : obj["result"].ToString();
}
示例12: ConvertToDictionary
public static Dictionary<string, object> ConvertToDictionary(object data)
{
var result = new Dictionary<string, object>();
if (data == null)
return result;
// Get all properties on the object
var allPriperties = data.GetType().GetProperties()
.Where(x => x.CanRead)
.Where(x => x.GetValue(data, null) != null)
.Where(x => !Attribute.IsDefined(x, typeof(QueryIgnore)));
var nonTaggedProperties = allPriperties.Where(x => !Attribute.IsDefined(x, typeof(QueryProperty)))
.ToDictionary(x => x.Name, x => x.GetValue(data, null));
var taggedProperties = allPriperties.Where(x => Attribute.IsDefined(x, typeof(QueryProperty)))
.ToDictionary(x => ((IEnumerable<QueryProperty>)x.GetCustomAttributes(typeof(QueryProperty), true)).First().Name, x => x.GetValue(data, null));
return result.Concat(taggedProperties).Concat(nonTaggedProperties).GroupBy(d => d.Key).ToDictionary(d => d.Key, d => d.First().Value);
}
示例13: GetMediaFilesList
public Dictionary<string, DateTime> GetMediaFilesList()
{
var searchOption = m_scanSubfolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var result = new Dictionary<string, DateTime>();
foreach (var searchPattern in GetFolderSearchPatternsList())
{
var filesList = Directory.GetFiles(m_path, searchPattern, searchOption);
m_totalItemsInProcess = filesList.Length;
m_currentProgress = 0;
m_logger.LogFormat(Resources.MediaMinerBase_GetMediaFilesList_Found__0__with__1__extension, m_totalItemsInProcess, searchPattern);
Dictionary<string, DateTime> interimResult = filesList.AsParallel()
.Select(p => new { File = p, TakenDate = GetTakenDateEntry(p) })
.Where(p => p.TakenDate != null).ToDictionary(p => p.File, p => p.TakenDate.Value);
result = result.Concat(interimResult).ToDictionary(p => p.Key, p => p.Value);
}
return result;
}
示例14: ConstructBasicParameters
protected IDictionary<string,object> ConstructBasicParameters(string url, MethodType methodType, Token token, params KeyValuePair<string,object>[] optionalParameters)
{
Enforce.NotNull(url, "url");
Enforce.NotNull(optionalParameters, "optionalParameters");
var parameters = new Dictionary<string, object>
{
{ "oauth_consumer_key", ConsumerKey },
{ "oauth_nonce", _random.Next() },
{ "oauth_timestamp", DateTime.UtcNow.ToUnixTime() },
{ "oauth_signature_method", "HMAC-SHA1" },
{ "oauth_version", "1.0" }
};
if (token != null)
parameters.Add("oauth_token", token.Key);
var signature = GenerateSignature(new Uri(url), methodType, token, parameters.Concat(optionalParameters));
parameters.Add("oauth_signature", signature);
return parameters;
}
示例15: loadAllExtensions
/// <summary>
/// Loads all extension assemblies from the given base directory and all his sub folders.
/// </summary>
/// <param name="t">The Type to search for.</param>
/// <param name="baseDirectory">The base directory.</param>
/// <param name="prefix">The prefix added to the directory name (normally the parents directory key).</param>
/// <returns>
/// Dictionary of key [EXT_(subfoldername)] and list of available class types
/// </returns>
static Dictionary<String, List<Type>> loadAllExtensions(Type t, string baseDirectory, string prefix)
{
Dictionary<String, List<Type>> dic = new Dictionary<String, List<Type>>();
if (t != null && Directory.Exists(baseDirectory))
{
//list all directly added types (without sub folder structure)
var baseypes = LoadTypes(t, baseDirectory);
if (baseypes != null && baseypes.Count > 0)
{
dic.Add(prefix, baseypes);
}
// list all sub directories
var subDirs = Directory.GetDirectories(baseDirectory);
if (subDirs != null && subDirs.Length > 0)
{
foreach (var subDir in subDirs)
{
try
{
if (Directory.Exists(subDir))
{
string name = new DirectoryInfo(subDir).Name;
name = (String.IsNullOrWhiteSpace(prefix) ? "" : (prefix + "_")) + name;
var subs = loadAllExtensions(t, subDir, name);
//combine the subs to the org
if (subs != null && subs.Count > 0)
{
dic = dic.Concat(subs).ToDictionary(x => x.Key, x => x.Value);
}
}
}
catch(Exception){}
}
}
}
return dic;
}