This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Collections.Generic | |
{ | |
public static class DictionaryExtension | |
{ | |
public static void ProcessValue<TKey, TValue>(this IDictionary<TKey, TValue> x, TKey key, Action<TValue> action) | |
{ | |
TValue o; | |
if (x.TryGetValue(key, out o)) | |
action(o); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Collections.Generic | |
{ | |
public static class ListExtensions | |
{ | |
/// <summary> | |
/// Do a binary search in a generic list | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <typeparam name="U"></typeparam> | |
/// <param name="tf">list</param> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Source: http://stackoverflow.com/questions/268321/bidirectional-1-to-1-dictionary-in-c-sharp | |
/// <summary> | |
/// This is a dictionary guaranteed to have only one of each value and key. | |
/// It may be searched either by TFirst or by TSecond, giving a unique answer because it is 1 to 1. | |
/// </summary> | |
/// <typeparam name="TFirst">The type of the "key"</typeparam> | |
/// <typeparam name="TSecond">The type of the "value"</typeparam> | |
using System.Collections.Generic; | |
using System; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int BinarySearch<T, U>(this TeaFile<T> tf, U target, Func<T, U> indexer) where T : struct | |
{ | |
var lo = 0; | |
var hi = (int)tf.Count - 1; | |
var comp = Comparer<U>.Default; | |
while(lo <= hi) | |
{ | |
var median = lo + (hi - lo >> 1); | |
var num = comp.Compare(indexer(tf.Items[median]), target); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
namespace System.Windows.Forms | |
{ | |
internal static class TreeViewExtensions | |
{ | |
internal static List<string> GetExpansionState(this TreeNodeCollection nodes) | |
{ | |
return nodes.Descendants() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ZedGraphExtensions | |
{ | |
/// <summary> | |
/// Change the Y axes order | |
/// </summary> | |
/// <param name="list">YAxisList</param> | |
/// <param name="pane">GraphPane</param> | |
/// <param name="index">index</param> | |
/// <param name="relativePos">relative position</param> | |
/// <returns>new index</returns> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions | |
{ | |
public static string GetUniqueKey(this IEnumerable<string> keys, string prefix, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase) | |
{ | |
int count = 0; | |
while (keys.FirstOrDefault(k => k.StartsWith(prefix + count, comparisonType)) != null) | |
count++; | |
return prefix + count; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Windows.Forms; | |
namespace Graph.UI.Tools | |
{ | |
public class MultiSelectTreeview : TreeView | |
{ | |
#region Selected Node(s) Properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
public class Ini | |
{ | |
Dictionary<string, Dictionary<string, string>> ini = new Dictionary<string, Dictionary<string, string>>(StringComparer.InvariantCultureIgnoreCase); | |
string file; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Arrange(Control container, int horizontalGap, int verticalGap, float aspectRatio) | |
{ | |
var H = container.Height; | |
var W = container.Width; | |
var N = container.Controls.OfType<Control>().Count(c => c.Visible); | |
if (N == 0) | |
return; | |
var bestSizedItem = ( |