Dictionaryd = new Dictionary () { {"Ram", 2}, {"Shyam", 1}, {"Hari", 0}, {"Kris", -1} }; foreach (KeyValuePair pair in d) { Console.WriteLine("{0}, {1}", pair.Key, pair.Value); }
Ram, 2 Shyam, 1 Hari, 0 Kris, -1
namespace EvanDangol.Reflection { class runnableAttribute : Attribute { } } public void InvokeFunction(string AssemblyName = null, string methodname = null) { try { Assembly asm; if (string.IsNullOrEmpty(AssemblyName)) { AssemblyName = "EvanDangol.dll"; } asm = Assembly.LoadFrom(AssemblyName); // string assem = Path.GetFileNameWithoutExtension(selectedfile) + "Tester"; //Type t = asm.GetTypes().Where(m => m.GetCustomAttributes(typeof(runnableAttribute), false).Length > 0).FirstOrDefault(); string assem = Path.GetFileNameWithoutExtension(selectedfile); string directory = Directory.GetParent(selectedfile).Name; Console.WriteLine(directory); Type t = asm.GetType(asm.GetName().Name + "." + "Tutorial" + "." +directory+"."+ assem); if (t != null) { var v = t.GetMethods(); var method = t.GetMethods() .Where(m => m.GetCustomAttributes(typeof(runnableAttribute), false).Length > 0) .FirstOrDefault(); method.Invoke(null, null); } } catch (NullReferenceException e) { MessageBox.Show(e.Message+ Environment.NewLine+ "I think Mr. Evan You Forgot To Add [runnable] attribute on top of your static class" ,"Missing static method with runnable attribute",MessageBoxButtons.OK,MessageBoxIcon.Question); } catch(ArgumentException ae) { MessageBox.Show(ae.Message + Environment.NewLine + "argument exception caught i guess line number 119"); } } }
namespace EvanDangol.Printing { public static class EvanPrinting { private static void CaptureScreen(Control c) { Graphics mygraphics = c.CreateGraphics(); Size s = c.Size; memoryImage = new Bitmap(s.Width, s.Height, mygraphics); Graphics memoryGraphics = Graphics.FromImage(memoryImage); IntPtr dc1 = mygraphics.GetHdc(); IntPtr dc2 = memoryGraphics.GetHdc(); BitBlt(dc2, 0, 0, c.ClientRectangle.Width, c.ClientRectangle.Height, dc1, 0, 0, 13369376); mygraphics.ReleaseHdc(dc1); memoryGraphics.ReleaseHdc(dc2); } [System.Runtime.InteropServices.DllImport("gdi32.dll")] public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop); private static Bitmap memoryImage; public static void DoPrinting(this Control c,bool OpenFileAfterSave) { CaptureScreen(c); memoryImage.Save("a.png"); // Create new pdf document and page PdfDocument doc = new PdfDocument(); PdfPage oPage = new PdfPage(); // Add the page to the pdf document and add the captured image to it doc.Pages.Add(oPage); XGraphics xgr = XGraphics.FromPdfPage(oPage); XImage img = XImage.FromFile("a.png"); xgr.DrawImage(img, 0, 0); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = ("PDF File|*.pdf"); DialogResult btnSave = saveFileDialog.ShowDialog(); if (btnSave.Equals(DialogResult.OK)) { doc.Save(saveFileDialog.FileName); doc.Close(); if(OpenFileAfterSave) { new EvanDangol.IO.EvanDirectory().OpenFile(saveFileDialog.FileName); } } img.Dispose(); } } }
namespace EvanDangol.Core { public delegate void EventHandler(object sender, IsAdminEventArgs e); //----------------------------------------------------------------------------------------------------- public class IsAdminEventArgs : EventArgs { public bool IsAdmin { get; set; } } //----------------------------------------------------------------------------------------------------- public class AdminSecurity { public event EventHandler LoginChanged; //----------------------------------------------------------------------------------------------------- protected virtual void BroadcastLoginChanged() { EventHandler handler = LoginChanged; if (handler != null) { IsAdminEventArgs e = new IsAdminEventArgs(); e.IsAdmin = this.IsAdmin; handler(this, e); } } private bool _IsAdmin; //----------------------------------------------------------------------------------------------------- public bool IsAdmin { get { return _IsAdmin; } set { _IsAdmin = value; BroadcastLoginChanged(); } } }
using EvanDangol.Core; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; namespace EvanDangol.Function { public enum EvanBaseNumber : byte { Binary = 2, Octal = 8, Hexadecimal = 16 }; public static class EvanFunction { public static void Print(this object AnyObject) { Console.WriteLine(AnyObject); } public static string GetBinaryValue(this string s) { StringBuilder sb = new StringBuilder(); string ss = s.GetAsciiValue(); string[] sa = ss.Trim().Split(' '); int[] temp = new int[sa.Length]; for (int i = 0; i < sa.Length; i++) { temp[i] = Convert.ToInt32(sa[i]); } foreach (int intt in temp) { sb.Append(intt.ConvertToBase(EvanBaseNumber.Binary) + " "); } return sb.ToString(); } public static int GetAsciiValue(this char c) { int i = (int)c; return i; } public static string GetAsciiValue(this string c) { StringBuilder sb = new StringBuilder(); int[] ii = new int[c.Length]; string[] ss = new string[c.Length]; char[] ch = c.Trim().ToCharArray(); for (int i = 0; i < ch.Length; i++) { ii[i] = (int)ch[i]; } foreach (int intt in ii) { sb.Append(intt + " "); } string s = sb.ToString(); return s; } public static string GetHexaDecimalValue(this string c) { StringBuilder sb = new StringBuilder(); int[] ii = new int[c.Length]; string[] ss = new string[c.Length]; char[] ch = c.Trim().ToCharArray(); for (int i = 0; i < ch.Length; i++) { ii[i] = (int)ch[i]; } for (int i = 0; i < ch.Length; i++) { ss[i] = string.Format("{0:X} ", ii[i]); } foreach (string intt in ss) { sb.Append(intt + " "); } string s = sb.ToString(); return s; } ////// This Function can convert integer number to any of 3 base numbers /// /// The Number You Like Toconvert /// Base Like "Binary" or "Hexadecimal" etc ///This Function Returns String Repesentation of BaseNumber public static string ConvertToBase(this int DecimalNumber, EvanBaseNumber baseToConvertTo) { int a = (byte)baseToConvertTo; return ConvertToBase(DecimalNumber, a); } ////// This Function can convert integer number to any base number /// /// number to convert /// base number ///string public static string ConvertToBase(this int DecimalNumber, int BaseNumber) { int result = 0; int iteration = 0; if (BaseNumber != 16) { do { int nextDigit = DecimalNumber % BaseNumber; result += nextDigit * (int)Math.Pow(10, iteration); iteration++; DecimalNumber /= BaseNumber; } while (DecimalNumber != 0); return result.ToString(); } else { string result1 = string.Format("{0:X}", DecimalNumber); return string.Format("0X{0}", result1); } } ////// this function converts integer to any of 3 base number /// /// any integer number /// /// string representation of base number binary or hexadecimal or octal /// also you can give "b","o","hex" or "h" or "bin",or "oct" but not "bi", "he",or "oc" /// ///string public static string ConvertToBase(this int DecimalNumber, string EvanBaseNumber) { string result = null; if (EvanBaseNumber.StartsWith("hex") || EvanBaseNumber == "h") { EvanBaseNumber = "hexadecimal"; } else if ( EvanBaseNumber.StartsWith("oct") || EvanBaseNumber == "o") { EvanBaseNumber = "octal"; } else if ( EvanBaseNumber.StartsWith("bin") || EvanBaseNumber == "b") { EvanBaseNumber = "binary"; } try { result = DecimalNumber.ConvertToBase((EvanBaseNumber)TypeDescriptor.GetConverter(typeof(EvanBaseNumber)).ConvertFrom(EvanBaseNumber)); } catch (Exception) { throw new EvanException(" \"" + EvanBaseNumber + "\" is not valid format"); } return result; } public static void swap(ref object a, ref object b) { object temp = a; a = b; b = temp; } public static void swap(ref T a, ref T b) { T temp = a; a = b; b = temp; } public static string ToBinary(this int number) { string s = ""; for (int t = 16384; t > 0; t = t / 2) { if ((t & number) != 0) { s += "1"; } else { s += "0"; } } #pragma warning disable for (int i = 0; i < s.Length; i++) { if (s.StartsWith("1")) return s; else { return s.TrimStart('0'); } } #pragma warning restored return s; } } }
namespace EvanDangol.Core { public static class EvanString { public static string ToTitleCase(this string inputString) { inputString = inputString.Trim(); inputString = inputString.ToLower(); string[] inputStringAsArray = inputString.Split(' '); StringBuilder sb = new StringBuilder(); for (int i = 0; i < inputStringAsArray.Length; i++) { if (inputStringAsArray[i].Length > 0) { sb.AppendFormat("{0}{1} ", inputStringAsArray[i].Substring(0, 1).ToUpper(), inputStringAsArray[i].Substring(1)); } } return sb.ToString(0, sb.Length - 1); } } }
using EvanDangol.Core; static void Main() { string s="hello from evan"; Console.WriteLine(s.ToTitleCase()); }
Hello From Evan