static void Main(string[] args) { List <int> intList = new List <int>(); // NOTE Lambda expression morphs into the shape of the object it is assigned to // NOTE: There is "Func" type taht can be used instead of creating our own delegates // NOTE: The last parameter in the "Func" is the return type int[] ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // x => x + 1; *implicitly typed, expression body* int[] temp = Array.FindAll(ints, x => x >= 7); // x => { return x + 1; } *implicitly typed, statement body* int[] temp1 = Array.FindAll(ints, x1 => { return(x1 > 7); }); // (int x) => x + 1; *explicitly typed, expression* int[] temp3 = Array.FindAll(ints, (int x) => x >= 7); // (int x) => { return x + 1; } *explicitly typed, statement body* TempDelegate myDelegete = (int x) => { return(x + 1); }; // (x, y) => x * y *multiple parameters* TempDelegate1 myDelegate1 = (int x, int y) => { return(Math.Sqrt(x * x + y * y)); }; // () => Console.WriteLine() *no parameters* TempDelegate2 myDelegate2 = () => { Console.WriteLine("This is a void delegate with lambda without parameters"); }; // NOTE: This is how we can replace a lambda expression with an anonymous method (a delegate) int[] temp2 = Array.FindAll(ints, delegate(int tempInt) { return(tempInt > 7); }); }
private void ThreadFunc(Object stateInfo) { if (this.Dispatcher.Thread != Thread.CurrentThread) { tempDelegate += new TempDelegate(time_tick); Dispatcher.Invoke(DispatcherPriority.Normal, tempDelegate); } }
private void TempPanel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (TempPanel.Visibility != Visibility.Visible) { return; } if (string.IsNullOrWhiteSpace(UserSettings.All.TemporaryFolder)) { //string.Format(@"ScreenToGif\Recording\{0}\", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")); UserSettings.All.TemporaryFolder = Path.GetTempPath(); } _tempDel = CheckTemp; _tempDel.BeginInvoke(e, CheckTempCallBack, null); #region Settings //Paths. AppDataPathTextBlock.Text = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ScreenToGif"), "Settings.xaml"); LocalPathTextBlock.Text = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.xaml"); //Remove all text decorations (Strikethrough). AppDataPathTextBlock.TextDecorations.Clear(); LocalPathTextBlock.TextDecorations.Clear(); //Clear the tooltips. AppDataPathTextBlock.ClearValue(ToolTipProperty); LocalPathTextBlock.ClearValue(ToolTipProperty); //AppData. if (!File.Exists(AppDataPathTextBlock.Text)) { AppDataPathTextBlock.TextDecorations.Add(new TextDecoration(TextDecorationLocation.Strikethrough, new Pen(Brushes.DarkSlateGray, 1), 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended)); AppDataPathTextBlock.SetResourceReference(ToolTipProperty, "TempFiles.NotExists"); } //Local. if (!File.Exists(LocalPathTextBlock.Text)) { LocalPathTextBlock.TextDecorations.Add(new TextDecoration(TextDecorationLocation.Strikethrough, new Pen(Brushes.DarkSlateGray, 1), 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended)); LocalPathTextBlock.SetResourceReference(ToolTipProperty, "TempFiles.NotExists"); } #endregion }
private void TempPanel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (TempPanel.Visibility != Visibility.Visible) { return; } if (string.IsNullOrWhiteSpace(Settings.Default.TemporaryFolder)) { //string.Format(@"ScreenToGif\Recording\{0}\", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")); Settings.Default.TemporaryFolder = Path.GetTempPath(); } _tempDel = CheckTemp; _tempDel.BeginInvoke(e, CheckTempCallBack, null); }
public static GUIContent Temp(string displayName) { if (tempDelegate != null) { return(tempDelegate(displayName)); } Type type = typeof(GUIContent); var mf = type.GetMethod("Temp", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(string) }, null); var action = (TempDelegate)Delegate.CreateDelegate(typeof(TempDelegate), mf); if (action == null) { throw new NullReferenceException("action"); } tempDelegate = action; return((GUIContent)mf.Invoke(null, new object[] { displayName })); }
public DelegateWrapper(TempDelegate td) { m_TD = td; }
private void TempPanel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { _tempDel = CheckTemp; _tempDel.BeginInvoke(e, CallBackConsulta, null); }