本文整理汇总了C#中System.Collections.Dictionary.Union方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Union方法的具体用法?C# Dictionary.Union怎么用?C# Dictionary.Union使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.Union方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button
/// <summary>
/// Кнопки без изменения ширины
/// метод добавляет в классы к существуюющему, но не перезаписует
/// </summary>
/// <param name="html">Current Html object in View</param>
/// <param name="text">Value of button</param>
/// <param name="htmlAttrsDic">Dictionary of html attributes</param>
/// <param name="useDefaultClasses">should use default classes</param>
/// <returns>Html button</returns>
public static MvcHtmlString Button(this HtmlHelper html, IDictionary<string, string> htmlAttrsDic,
string text = "Send Data", bool useDefaultClasses = true)
{
TagBuilder tag = new TagBuilder("input");
IDictionary<string, string> attributes = new Dictionary<string, string>()
{
{"type", _btnType},
{"value", text}
};
if (useDefaultClasses)
{
attributes.Add(_class, _btnClass);
var res = htmlAttrsDic.SingleOrDefault(z => z.Key == _class);
if (res.Key != null)
{
attributes[res.Key] += " " + res.Value;
htmlAttrsDic.Remove(res.Key);
}
}
attributes = attributes
.Union(htmlAttrsDic)
.ToDictionary(z => z.Key, v => v.Value);
tag.MergeAttributes(attributes);
return new MvcHtmlString(tag.ToString(TagRenderMode.SelfClosing));
}
示例2: AddRangeTest_ShouldAddAllElement_IfDistinctDictionaryIsPassed
public void AddRangeTest_ShouldAddAllElement_IfDistinctDictionaryIsPassed()
{
// Arrange
var dictionary = new Dictionary<string, int>();
dictionary.Add("a", 1);
dictionary.Add("d", 4);
dictionary.Add("b", 2);
dictionary.Add("c", 3);
dictionary.Add("e", 5);
var target = new Dictionary<string, int>();
// Act
target.AddRange(dictionary);
// Assert
CollectionAssert.AreEqual(
new int[] { 1, 2, 3, 4, 5 }.AsEnumerable(),
target.Union(dictionary, (_1, _2) => _1.Is(_2)).
OrderBy(_ => _.Key).
Select(_=>_.Value)
);
}
示例3: SourcesController
SourcesController(SourcesControl AView, PresentationInfo APresentation)
{
_instance = this;
_view = AView;
resourceNodes = new Dictionary<ResourceDescriptor, ISourceNode>();
m_presentation = APresentation = new PresentationInfo(APresentation); //избавляемся от *Ext
Dictionary<string, IList<ResourceDescriptor>> local_rd = DesignerClient.Instance.PresentationWorker.GetLocalSources(APresentation.UniqueName);
Dictionary<string, IList<ResourceDescriptor>> common_rd = DesignerClient.Instance.PresentationWorker.GetGlobalSources();
global_categories = new Dictionary<string, SourceCategory>();
local_categories = new Dictionary<string, SourceCategory>();
List<String> sourceTypes = new List<string>();
foreach (SourceType t in _config.ModuleConfiguration.SourceList)
{
if (!sourceTypes.Contains(t.Type))
{
sourceTypes.Add(t.Type);
if (!(t.IsHardware))
{
SourceCategory local_cat = new SourceCategory(t, false) { Icon = Properties.Resources.soft };
local_categories.Add(t.Type, local_cat);
}
SourceCategory global_cat = new SourceCategory(t, true) { Icon = Properties.Resources.soft };
global_categories.Add(t.Type, global_cat);
}
}
foreach (var rd in local_rd.Union(common_rd))
{
foreach (var r in rd.Value)
{
if (r.ResourceInfo is INonVisibleResource)
{
nonVisibleResources.Add(r);
}
}
}
/// Сортировка источников: сперва программные, потом аппаратные, в каждой группе -- по названию.
foreach (var category in global_categories.Union(local_categories).OrderBy(gos => gos.Value.IsHardware ? "1" + gos.Key: "0" + gos.Key))
{
IEnumerable<ResourceDescriptor> e = new List<ResourceDescriptor>();
if (local_rd.ContainsKey(category.Key))
e = local_rd[category.Key];
if (common_rd.ContainsKey(category.Key))
e = e.Union(common_rd[category.Key]);
foreach (ResourceDescriptor resource in e/*.OrderBy(res=>res.ResourceInfo.Name)*/)
{
if (!(resource is BackgroundImageDescriptor) && !(resource is INonVisibleResource))
{
ISourceNode node = null;
SourceType type = null;
if (resource.ResourceInfo.IsHardware)
type = _config.ModuleConfiguration.SourceList.Where(t => t.Name == resource.ResourceInfo.Name && t.Type == resource.ResourceInfo.Type).FirstOrDefault();
else
type = category.Value.Type;
if (type != null)
node = new SourceWindow(resource) { SourceType = type };
if (node != null)
{
if ((category.Value.Global && !resource.IsLocal) || (!category.Value.Global && resource.IsLocal))
{
category.Value.Resources.Add(node);
resourceNodes.Add(resource, node);
}
if (resource.ResourceInfo != null && resource.ResourceInfo.IsHardware && type != null)
{
node.IsOnline = ShowClient.Instance.IsOnLine(type);
}
}
}
else
{
if (resource.ResourceInfo is INonVisibleResource)
{
nonVisibleResources.Add(resource);
}
}
}
_view.AddSourceCategory(category.Value, category.Value.Global);
}
_view.SelectFirstGlobalSource();
//.........这里部分代码省略.........
示例4: FindStatementSymbolsInTree
private Dictionary<ISymbolicExpressionTreeNode, int> FindStatementSymbolsInTree(ISymbolicExpressionTreeNode node, IEnumerable<string> productions, ref int curline) {
Dictionary<ISymbolicExpressionTreeNode, int> symbolToLineDict = new Dictionary<ISymbolicExpressionTreeNode, int>();
if (node.Subtrees.Count() > 0) {
// node
var symbol = node.Symbol as CFGSymbol;
if (symbol != null) {
var partsEnumerator = symbol.GetTerminalParts().GetEnumerator();
var subtreeEnumerator = node.Subtrees.GetEnumerator();
if (productions.Contains(symbol.Name)) {
symbolToLineDict.Add(node, curline);
}
while (partsEnumerator.MoveNext() && subtreeEnumerator.MoveNext()) {
curline += partsEnumerator.Current.Count(c => c == '\n');
symbolToLineDict = symbolToLineDict.Union(FindStatementSymbolsInTree(subtreeEnumerator.Current, productions, ref curline)).ToDictionary(k => k.Key, v => v.Value);
}
curline += partsEnumerator.Current.Count(c => c == '\n');
} else {
// ProgramRoot or StartSymbol
foreach (var subtree in node.Subtrees) {
symbolToLineDict = symbolToLineDict.Union(FindStatementSymbolsInTree(subtree, productions, ref curline)).ToDictionary(k => k.Key, v => v.Value);
}
}
} else {
// leaf
var symbol = node.Symbol as CFGSymbol;
if (productions.Contains(symbol.Name)) {
symbolToLineDict.Add(node, curline);
}
var parts = symbol.GetTerminalParts();
curline += parts.First().Count(c => c == '\n');
}
return symbolToLineDict;
}
示例5: UnionShouldMergeDictionariesWithComparer
public void UnionShouldMergeDictionariesWithComparer()
{
// arrange
var d1 = new Dictionary<string, int>()
{
{ "Key1", 1 },
{ "Key3", 3 },
{ "Key5", 5 }
};
var d2 = new Dictionary<string, int>()
{
{ "Key1", 1 },
{ "Key2", 2 },
{ "Key4", 4 }
};
// act
var actual = d1.Union( d2, StringComparer.Ordinal );
// assert
Assert.Equal( 5, actual.Count );
Assert.True( actual.ContainsKey( "Key1" ) );
Assert.True( actual.ContainsKey( "Key2" ) );
Assert.True( actual.ContainsKey( "Key3" ) );
Assert.True( actual.ContainsKey( "Key4" ) );
Assert.True( actual.ContainsKey( "Key5" ) );
}