This file contains hidden or 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 bool Deserialize<T>(this String str, out T item) | |
| { | |
| item = default(T); | |
| try | |
| { | |
| using (var reader = XmlReader.Create(new StringReader(str))) | |
| { | |
| item = (T)new XmlSerializer(typeof(T)).Deserialize(reader); | |
| } | |
| return true; |
This file contains hidden or 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 class Class1 | |
| { | |
| internal static int Myvar; | |
| private int _myVar; | |
| public int MyVar1 | |
| { | |
| get{return this.GetType().IsSubclassOf(typeof(Class1)) ? Myvar : _myVar;} | |
| set{_myVar = value;Myvar = value;} | |
| } | |
| } |
This file contains hidden or 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
| //add reference System.Data | |
| //add reference System.Web.extensions | |
| //add reference System.Web.DataTableExtensions | |
| public static string ConvertToJson(DataTable dt, int page = 0, int count = 100) | |
| { | |
| var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); | |
| var rows = new List<Dictionary<string, object>>(); | |
| foreach (DataRow dr in dt.AsEnumerable().Skip(page * count).Take(count).ToList()) | |
| { | |
| rows.Add(dt.Columns.Cast<DataColumn>().ToDictionary(col => col.ColumnName, col => dr[col])); |
This file contains hidden or 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 Diff(this string first, string second) | |
| { | |
| var s1 = first.ToCharArray(); | |
| var s2 = second.ToCharArray(); | |
| int s1P = s1.Length, s2P = s2.Length; | |
| var num = new int[s1P + 1, s2P + 1]; | |
| // fill array | |
| for (var i = 1; i <= s1P; i++) |
This file contains hidden or 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 | |
| { | |
| private const double DaysInYear = 365.242; | |
| private const double DaysInMonth = 30.4368; | |
| public static int GetDays(this TimeSpan ts) | |
| { | |
| return (int)((ts.TotalDays % DaysInYear % DaysInMonth)); | |
| } | |
| public static int GetMonths(this TimeSpan ts) |
This file contains hidden or 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
| [DllImport("gdi32")] | |
| private static extern IntPtr CreateEllipticRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); | |
| [DllImport("dwmapi")] | |
| private static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DwmBlurbehind pBlurBehind); | |
| public struct DwmBlurbehind | |
| { | |
| public int DwFlags; | |
| public bool FEnable; | |
| public IntPtr HRgnBlur; | |
| public bool FTransitionOnMaximized; |
This file contains hidden or 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 bool DeserializeJson<T>(this String str, out T item) | |
| { | |
| item = default(T); | |
| try | |
| { | |
| item = new JavaScriptSerializer().Deserialize<T>(str); | |
| return true; | |
| } |
This file contains hidden or 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 bool Push<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value) | |
| { | |
| try | |
| { | |
| if (dictionary.ContainsKey(key)) | |
| { | |
| dictionary[key] = value; | |
| } |
This file contains hidden or 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
| class MyClass | |
| { | |
| static Dictionary<string, Func<MyClass, string, bool>> commands | |
| = new Dictionary<string, Func<MyClass, string, bool>> | |
| { | |
| { "Foo", (@this, x) => @this.Foo(x) }, | |
| { "Bar", (@this, y) => @this.Bar(y) } | |
| }; | |
| public bool Execute(string command, string value) |
This file contains hidden or 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
| //PM> Install-Package Rx-Linq | |
| readonly List<string> _list = new List<string> { "http://www.google.com", "https://www.gmail.com", "http://www.aripaev.ee" }; | |
| private readonly string format = "[{0}] {1} : {2} [{3}]"; | |
| [Category("WebClient")] | |
| [TestCase("sync" )] | |
| public void SynchronousTest(string name) | |
| { | |
| DateTime start = DateTime.Now; | |
| var dict = _list.ToDictionary(o => o, o => new WebClient().DownloadString(new Uri(o))); | |
| dict.Keys.ToList().ForEach(o => Console.WriteLine(format, DateTime.Now - start, o, dict[o].Length, name)); |