本文整理汇总了C#中Dictionary.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Merge方法的具体用法?C# Dictionary.Merge怎么用?C# Dictionary.Merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Diagnostic
/// <summary>
/// Diagnostics the specified base URL.
/// </summary>
/// <param name="baseUrl">The base URL.</param>
/// <param name="paths">The paths.</param>
/// <returns></returns>
public static Dictionary<string, bool> Diagnostic(string baseUrl, params string[] paths)
{
Dictionary<string, bool> result = new Dictionary<string, bool>();
if (!string.IsNullOrWhiteSpace(baseUrl) && paths.HasItem())
{
Parallel.ForEach(paths, (path) =>
{
var httpRequest = string.Format("{0}/{1}", baseUrl.TrimEnd(' ', '/'), path.TrimStart('/', ' ')).CreateHttpWebRequest();
try
{
var response = httpRequest.GetResponse();
var length = response.ContentLength;
result.Merge(httpRequest.RequestUri.ToString(), true);
}
catch
{
result.Merge(httpRequest.RequestUri.ToString(), false);
}
});
}
return result;
}
示例2: GetApiDocumentationAttributesAndReturnTypes
private Dictionary<ApiDocumentationAttribute, Type> GetApiDocumentationAttributesAndReturnTypes( Type controllerType )
{
var result = new Dictionary<ApiDocumentationAttribute, Type>();
var methods = GetControllerMethods( controllerType );
var methodAttributesAndReturnTypes = GetMethodsAttributesAndReturnTypes( methods );
var classAttributesAndReturnTypes = GetClassAttributesAndReturnTypes( controllerType );
result.Merge( methodAttributesAndReturnTypes );
result.Merge( classAttributesAndReturnTypes );
return result;
}
示例3: V
public static ICode V(ICode ast) {
var ctx = ast.Ctx;
var blockInfo = VisitorSubstituteIrreducable.FindSuitableBlocks.GetInfo(ast);
var bInfo = blockInfo.Select(x => new {
toCount = VisitorContToCounter.GetCount(x.Key, ast),
ast = x.Key,
codeCount = x.Value.numICodes,
}).ToArray();
var block = bInfo.Where(x => x.toCount >= 2).OrderBy(x => x.toCount * x.codeCount).FirstOrDefault();
if (block == null) {
return ast;
}
var phis = new Dictionary<Expr,Expr>();
var blockCopies = Enumerable.Range(0, block.toCount - 1)
.Select(x => {
var v = new VisitorDuplicateCode();
var ret = v.Visit(block.ast);
phis = phis.Merge(v.phiMap, (a, b) => new ExprVarPhi(ctx) { Exprs = new[] { a, b } });
return ret;
})
.Concat(block.ast)
.ToArray();
var contTos = VisitorFindContinuationsRecursive.Get(ast).Where(x => x.To == block.ast).ToArray();
for (int i = 0; i < contTos.Length; i++) {
var contTo = contTos[i];
var blockCopy = blockCopies[i];
ast = VisitorReplace.V(ast, contTo, blockCopy);
}
ast = VisitorReplaceExprUse.V(ast, phis);
return ast;
}
示例4: MergeReturnsSourceIfDictToMergeIsNull
public void MergeReturnsSourceIfDictToMergeIsNull()
{
var source = new Dictionary<string, string> { { "key", "value" } };
var candidate = source.Merge(null);
Assert.IsNotNull(candidate);
Assert.AreSame(source, candidate);
}
示例5: GetApiContracts
/// <summary>
/// Gets the API contracts.
/// </summary>
/// <returns>RemoteInvokeResult.</returns>
public SandboxMarshalInvokeResult GetApiContracts()
{
SandboxMarshalInvokeResult result = new SandboxMarshalInvokeResult();
try
{
Dictionary<string, string> interfaces = new Dictionary<string, string>();
foreach (var one in EnvironmentCore.DescendingAssemblyDependencyChain)
{
foreach (var item in one.GetTypes())
{
if (item.IsInterface && item.HasAttribute<ApiContractAttribute>() && !item.IsGenericTypeDefinition)
{
interfaces.Merge(item.GetFullName(), item.Name, false);
}
}
}
result.SetValue(interfaces);
}
catch (Exception ex)
{
result.SetException(ex.Handle());
}
return result;
}
示例6: ForScope
public IDictionary<string, object> ForScope(string path)
{
IDictionary<string, object> result = new Dictionary<string, object>();
if (path == null) return result;
if (path.Length > 0)
{
result = result.Merge(ForScope(Path.GetDirectoryName(path)));
}
if (_scopedValues.ContainsKey(path))
{
result = result.Merge(_scopedValues[path]);
}
return result;
}
示例7: Merge_with_object_should_add_specified_items
public void Merge_with_object_should_add_specified_items()
{
IDictionary<string, object> target = new Dictionary<string, object>();
target.Merge(new { foo = "bar" });
Assert.Equal("bar", target["foo"]);
}
示例8: Merge_with_object_should_not_replace_the_existing_items
public void Merge_with_object_should_not_replace_the_existing_items()
{
IDictionary<string, object> target = new Dictionary<string, object> { { "foo", "bar" } };
target.Merge(new { foo = "bar2" }, false);
Assert.Equal("bar", target["foo"]);
}
示例9: DuplicatesAreNotOverwrittenByDefault
public void DuplicatesAreNotOverwrittenByDefault()
{
var source = new Dictionary<string, string> { { "key", "value" } };
var candidate = source.Merge(new Dictionary<string, string> { { "key", "value2" } });
Assert.IsNotNull(candidate);
Assert.AreEqual(1, candidate.Count);
Assert.AreEqual("value", candidate["key"]);
}
示例10: DuplicatesOverwriteIfSpecified
public void DuplicatesOverwriteIfSpecified()
{
var source = new Dictionary<string, string> { { "key", "value" } };
var candidate = source.Merge(new Dictionary<string, string> { { "key", "value2" } }, true);
Assert.IsNotNull(candidate);
Assert.AreEqual(1, candidate.Count);
Assert.AreEqual("value2", candidate["key"]);
}
示例11: Should_be_able_to_merge_item
public void Should_be_able_to_merge_item()
{
IDictionary<string, object> target = new Dictionary<string, object>();
target.Merge("key", "value", true);
Assert.True(target.ContainsKey("key"));
}
示例12: LogWarning
public static void LogWarning(Exception ex, Dictionary<string, string> attributes = null)
{
var attr = attributes.Merge(new Dictionary<string, string>
{
{"Exception", ex.Message},
{"Stack", ex.StackTrace}
});
Session.TagEvent("Warning", attr);
}
示例13: DictionariesAreMerged
public void DictionariesAreMerged()
{
var source = new Dictionary<string, string> { { "key", "value" } };
var candidate = source.Merge(new Dictionary<string, string> { { "key2", "value2" } });
Assert.IsNotNull(candidate);
Assert.AreEqual(2, candidate.Count);
Assert.AreEqual("value", candidate["key"]);
Assert.AreEqual("value2", candidate["key2"]);
}
示例14: Match
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
var attributeRoute = (IAttributeRoute)route;
var allDefaults = new Dictionary<string, object>();
allDefaults.Merge(attributeRoute.Defaults);
allDefaults.Merge(attributeRoute.QueryStringDefaults);
// If the param is optional and has no value, then pass the constraint
if (allDefaults.ContainsKey(parameterName) && allDefaults[parameterName] == UrlParameter.Optional)
{
if (values[parameterName].HasNoValue())
{
return true;
}
}
return _constraint.Match(httpContext, route, parameterName, values, routeDirection);
}
示例15: GetControllerModels
public Dictionary<string, ApiDocModel> GetControllerModels( Type controllerType )
{
var result = new Dictionary<String, ApiDocModel>();
foreach ( var apiDocumentationAttributesAndReturnType in GetApiDocumentationAttributesAndReturnTypes( controllerType ) )
{
result.Merge( _modelsGenerator.GetModels( apiDocumentationAttributesAndReturnType.Key.ReturnType ?? apiDocumentationAttributesAndReturnType.Value ) );
}
return result;
}