internal static int checkDelegate(IntPtr l,int p,out Deleg.SimpleDelegate ua) { int op = extractFunction(l,p); if(LuaDLL.lua_isnil(l,p)) { ua=null; return op; } else if (LuaDLL.lua_isuserdata(l, p)==1) { ua = (Deleg.SimpleDelegate)checkObj(l, p); return op; } LuaDelegate ld; checkType(l, -1, out ld); if(ld.d!=null) { ua = (Deleg.SimpleDelegate)ld.d; return op; } LuaDLL.lua_pop(l,1); l = LuaState.get(l).L; ua = (string a1,UnityEngine.GameObject a2) => { int error = pushTry(l); pushValue(l,a1); pushValue(l,a2); ld.pcall(2, error); LuaDLL.lua_settop(l, error-1); }; ld.d=ua; return op; }
static void Main(string[] args) { SomeClass SC = new SomeClass(); Del del = new Del(SC.Method); // // // string s = del(10, true); Console.WriteLine(s); Console.ReadKey(); DelStat delStat = new DelStat(SomeClass.MethodStat); int p = 50; delStat(ref p); Console.WriteLine(p); Console.ReadKey(); Deleg deleg = new Deleg(Method); BaseClass BC = deleg("First name"); Console.WriteLine(BC.name); Console.ReadKey(); }
static public int callDAction_s(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif Deleg.callDAction(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int testFunc_s(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif System.Func <System.Int32> a1; checkDelegate(l, 1, out a1); Deleg.testFunc(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
public MyTimer(Deleg Func) { this.f = Func; Thread t = new Thread(loop); t.IsBackground = true; //NECESARIO para que acabe o fío cando acabe o main!!! t.Start(); }
static public int constructor(IntPtr l) { Deleg o; o = new Deleg(); pushObject(l, o); return(1); }
public MyTimer(Deleg leaderDeleg) { this.leaderDeleg = leaderDeleg; Thread secondThread = new Thread(start);//inicio start secondThread.IsBackground = true; secondThread.Start(); }
private void button1_Click(object sender, EventArgs e) { Circle C = new Circle(50, 100, 50); Deleg circleShow = C.Show; Pen pen = new Pen(Brushes.Red); Graphics circle = pictureBox1.CreateGraphics(); circle.DrawEllipse(pen, C.CenterX, C.CenterY, C.Radius * 2, C.Radius * 2); circle.DrawString($"{circleShow()}\nПлоща кола: {C.Area()}", new Font("Arial", 10), Brushes.Green, 2, 2); }
static void Main(string[] args) { List <int> findArr = new List <int>(); Stopwatch timer = new Stopwatch(); DateTime start = DateTime.Now; for (int i = 0; i < 10000; i++) { findArr = FindPositive(); } DateTime end = DateTime.Now; Console.WriteLine("Method 1 average: {0} msec", end - start); start = DateTime.Now; for (int i = 0; i < 10000; i++) { Deleg deleg = new Deleg(IsPositive); findArr = Find(deleg); } end = DateTime.Now; Console.WriteLine("Method 2 average: {0} msec", end - start); start = DateTime.Now; for (int i = 0; i < 10000; i++) { findArr = Find(delegate(int number) { return(number > 0); }); } end = DateTime.Now; Console.WriteLine("Method 3 average: {0} msec", end - start); start = DateTime.Now; for (int i = 0; i < 10000; i++) { findArr = Find(number => number > 0); } end = DateTime.Now; Console.WriteLine("Method 4 average: {0} msec", end - start); start = DateTime.Now; for (int i = 0; i < 10000; i++) { findArr = (from number in arr where number > 0 select number).ToList(); } end = DateTime.Now; Console.WriteLine("Method 5 average: {0} msec", end - start); Console.ReadKey(); }
static public int callDAction_s(IntPtr l) { try { Deleg.callDAction(); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
/* tambien se podria hacer el atributo d publico y que se asignen las * funciones directamente desde el program. */ public void suscripcionSinEventos(Deleg param) { if (this.d == null) { this.d = param; } else { this.d += param; } }
private static void Main(string[] args) { Deleg delegSort = Sort; string[] data = { "ss", "aa", "a", "abc" }; Console.WriteLine(string.Join(" ", data)); delegSort(data);//todo np ты не понял задания. Нужно передавать делегат сравнения, а не весь метод сортировки. "Реализовать метод сравнения строк отдельным методом, передаваемым в сортировку через делегат." Console.ReadKey(); }
static public int callDAction_s(IntPtr l) { try { Deleg.callDAction(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
public void Do() { A.Invoke(this, new AlarmEventArgs { Info = "Все хорошо" }); // Правильное использование событий. // Проверка не нужна из-за пустого делегата при инициализации Deleg deleg = new Deleg(delegate { }); Delegate @delegate = deleg; deleg.Invoke(); @delegate.DynamicInvoke(); }
static public int testFunc_s(IntPtr l) { try { System.Func <System.Int32> a1; checkDelegate(l, 1, out a1); Deleg.testFunc(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int testDAction_s(IntPtr l) { try { System.Action <System.Int32, System.Collections.Generic.Dictionary <System.Int32, System.Object> > a1; LuaDelegation.checkDelegate(l, 1, out a1); Deleg.testDAction(a1); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int testFunc_s(IntPtr l) { try{ System.Func <System.Int32> a1; checkDelegate(l, 1, out a1); Deleg.testFunc(a1); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int testAction_s(IntPtr l) { try { System.Action <System.Int32, System.String> a1; checkDelegate(l, 1, out a1); Deleg.testAction(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int testDAction_s(IntPtr l) { try { System.Action <System.Int32, System.Collections.Generic.Dictionary <System.Int32, System.Object> > a1; checkDelegate(l, 1, out a1); Deleg.testDAction(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int testAction_s(IntPtr l) { try { System.Action <System.Int32, System.String> a1; LuaDelegation.checkDelegate(l, 1, out a1); Deleg.testAction(a1); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
private void button2_Click(object sender, EventArgs e) { Trapezoid T = new Trapezoid(50, 150, 100, 150, 180, 200, 25, 200); Deleg trapezoidShow = T.Show; Pen pen = new Pen(Brushes.Blue); Graphics trapezoid = pictureBox1.CreateGraphics(); trapezoid.DrawLine(pen, T.CenterX, T.CenterY, T.RightTopX, T.RightTopY); trapezoid.DrawLine(pen, T.RightTopX, T.RightTopY, T.RightBottomX, T.RightBottomY); trapezoid.DrawLine(pen, T.RightBottomX, T.RightBottomY, T.LeftBottomX, T.LeftBottomY); trapezoid.DrawLine(pen, T.LeftBottomX, T.LeftBottomY, T.CenterX, T.CenterY); trapezoid.DrawString($"{trapezoidShow()}\nПлоща трапеції: {T.Area()}", new Font("Arial", 10), Brushes.Green, 2, 220); }
static public int getFunc_s(IntPtr l) { try { System.Func <System.Int32, System.String, System.Boolean> a1; checkDelegate(l, 1, out a1); var ret = Deleg.getFunc(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
// Get the information about the asset and displays it public void ShowAsset( IVRBranch branch ) { AssetDatas assetDatas = new AssetDatas( branch ); if( _currentAssetView == null ) { _currentAssetView = ( AssetView )AssetDatasViewer.CurrentViewer.UI.OpenForm( typeof( AssetView ) ); _currentAssetView.FormClosing += new FormClosingEventHandler( assetView_Closed ); } mDeleg_DocumentsAndScada = new Deleg( _service.GetAssetDocumentsAndScada ); AsyncCallback callback_DocumentsAndScada = new AsyncCallback( buildAssetView ); mDeleg_DocumentsAndScada.BeginInvoke( assetDatas, callback_DocumentsAndScada, null ); }
static List <int> Find(Deleg deleg) { List <int> result = new List <int>(); foreach (int elem in arr) { if (deleg(elem)) { result.Add(elem); } } return(result); }
static public int constructor(IntPtr l) { LuaDLL.lua_remove(l, 1); Deleg o; if (matchType(l, 1)) { o = new Deleg(); pushObject(l, o); return(1); } LuaDLL.luaL_error(l, "New object failed."); return(0); }
static public int getFunc_s(IntPtr l) { try { System.Func <System.Int32, System.String, System.Boolean> a1; LuaDelegation.checkDelegate(l, 1, out a1); var ret = Deleg.getFunc(a1); pushValue(l, ret); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int setcallback2_s(IntPtr l) { try { System.Action <System.Int32> a1; checkDelegate(l, 1, out a1); System.Action <System.String> a2; checkDelegate(l, 2, out a2); Deleg.setcallback2(a1, a2); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int setcallback2_s(IntPtr l) { try { System.Action <System.Int32> a1; LuaDelegation.checkDelegate(l, 1, out a1); System.Action <System.String> a2; LuaDelegation.checkDelegate(l, 2, out a2); Deleg.setcallback2(a1, a2); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static void Main(string[] args) { //创建一个委托 Deleg proc = new Deleg(WriteSum); //采用异步方式调用委托 //指定SumDone为异步操作完成后的回调函数 //指定ev为object参数,用于同步回调函数与主线程间操作 IAsyncResult async = proc.BeginInvoke(10, 20, SumDone, ev); Console.WriteLine("主线程ID号为:{0},异步操作已开始执行,正等待操作完成。", Thread.CurrentThread.ManagedThreadId); //等待异步操作完成 ev.WaitOne(); Console.WriteLine("异步操作已完成!"); System.Console.ReadKey(); }
public void MaterialTest() { Student[] users = new Student[] { new Student("FirstName", "LastName") { Account = { Sum = 50 } }, new Student("FirstName", "LastName") { Account = { Sum = 150 } }, new Student("FirstName", "LastName") { Account = { Sum = 250 } } }; string[] strings = new string[3]; //Material material1 = new Material("Material 1"); //Material material2 = new Material("Material 2"); //Material material3 = new Material("Material 3"); //user.Account.Added += material1.Message; //user.Account.Added += material2.Message; //user.Account.Added += material3.Message; Deleg deleg = null; foreach (Student user in users) { user.Account.Added += message => $"The account has arrived {user.Account.Sum}"; deleg += user.Account.OnAdded; } deleg?.Invoke(); for (int i = 0; i < users.Length; i++) { strings[i] = users[i].Account.Message; } //Assert.Fail(); }
private static void DelegateExample() { var dg = new Deleg(); dg.OnClick += D_OnClick; dg.OnClick += D_OnClick1; d.OnClick += D_OnClick; d.OnClick += D_OnClick; d.OnClick += D_OnClick1; d.OnClick += D_OnClick1; var str = Console.ReadLine(); dg.Call(str); Console.WriteLine(""); d.Call(str); }
internal static int checkDelegate(IntPtr l,int p,out Deleg.GetBundleInfoDelegate ua) { int op = extractFunction(l,p); if(LuaDLL.lua_isnil(l,p)) { ua=null; return op; } else if (LuaDLL.lua_isuserdata(l, p)==1) { ua = (Deleg.GetBundleInfoDelegate)checkObj(l, p); return op; } LuaDelegate ld; checkType(l, -1, out ld); if(ld.d!=null) { ua = (Deleg.GetBundleInfoDelegate)ld.d; return op; } LuaDLL.lua_pop(l,1); l = LuaState.get(l).L; ua = (string a1,out System.String a2,out System.Int32 a3) => { int error = pushTry(l); pushValue(l,a1); ld.pcall(1, error); bool ret; checkType(l,error+1,out ret); checkType(l,error+2,out a2); checkType(l,error+3,out a3); LuaDLL.lua_settop(l, error-1); return ret; }; ld.d=ua; return op; }
public void DelegCall(Deleg obj) { obj(); }
private void button1_Click(object sender, EventArgs e) { int hhh, hhhn; h = Convert.ToInt32(textBox1.Text); m = Convert.ToInt32(textBox2.Text); s = Convert.ToInt32(textBox3.Text); zadan = Convert.ToString(textBox4.Text); Class1 rab1 = new Class1(); hhh = h * 3600 + m * 60 + s; hhhn = h * 3600 + m * 60 + s; while (hhh >= 0) { Thread.Sleep(1000); hhh = rab1.Start1(hhh, hhhn, zadan); h = hhh / 3600; m = (hhh - h * 3600) / 60; s = hhh - h * 3600 - m * 60; label1.Text = Convert.ToString(h); label3.Text = Convert.ToString(m); label5.Text = Convert.ToString(s); label1.Refresh(); label3.Refresh(); label5.Refresh(); } h = Convert.ToInt32(textBox5.Text); m = Convert.ToInt32(textBox6.Text); s = Convert.ToInt32(textBox7.Text); zadan = Convert.ToString(textBox8.Text); Class2 rab2 = new Class2(); rab2.Nachalo += delegate // обрабатываем события с помощью анонимных делегатов { MessageBox.Show("Начало отсчёта! " + zadan); }; rab2.Konez += delegate // добавление ссылки на другое анонимное событие { MessageBox.Show("Обратный отсчёт завершён!"); }; Deleg2 del = new Deleg2(rab2.Start1); // Создаем переменную делегата и связываем c методом hhh = h * 3600 + m * 60 + s; hhhn = h * 3600 + m * 60 + s; while (hhh >= 0) { hhh = del(hhh, hhhn, zadan); //сработал делегат if (hhh >= 0) { h = hhh / 3600; m = (hhh - h * 3600) / 60; s = hhh - h * 3600 - m * 60; Preob(h, m, s); } } h = Convert.ToInt32(textBox10.Text); m = Convert.ToInt32(textBox11.Text); s = Convert.ToInt32(textBox12.Text); zadan = Convert.ToString(textBox9.Text); Class3 rab3 = new Class3(); Deleg del3 = (h1, m1, s1, zadan1) => h * 3600 + m * 60 + s - 1;// Создаем переменную делегата с помощью лямбда-выражения rab3.Nach(zadan); while (h + m + s > 0) { Thread.Sleep(1000); hhh = del3(h, m, s, zadan); //сработал делегат h = hhh / 3600; m = (hhh - h * 3600) / 60; s = hhh - h * 3600 - m * 60; label1.Text = Convert.ToString(h); label3.Text = Convert.ToString(m); label5.Text = Convert.ToString(s); label1.Refresh(); label3.Refresh(); label5.Refresh(); } rab3.Kon(zadan); }
private void button_Click(object sender, EventArgs e) { if (((Button)sender).FlatStyle == System.Windows.Forms.FlatStyle.Popup) { ((Button)sender).FlatStyle = System.Windows.Forms.FlatStyle.Flat; /* int param.countheight = this.Height / height; int param.countwidth = this.Width / width; int x = ((Button)sender).Left / width; int y = ((Button)sender).Top / height; */ ((Button)sender).Tag = figure.id; if ((int)((Button)sender).Tag == figure.circle) ((Button)sender).Image = Client.Properties.Resources.circle; else ((Button)sender).Image = Client.Properties.Resources.cross; Field.test = new Deleg(Field.win_func); control(((Button)sender).Tag, figure.id); Field.test = new Deleg(Field.line); control(((Button)sender).Tag, figure.id); ii(); for (int i = 0; i < param.countheight; i++) for (int j = 0; j < param.countwidth; j++) but[i * param.lim + j].Text = ""; } }
public void ii() { but[key] = max(); but[key].Text = ""; but[key].FlatStyle = System.Windows.Forms.FlatStyle.Flat; but[key].Tag = -figure.id; if ((int)but[key].Tag == figure.circle) but[key].Image = Client.Properties.Resources.circle; else but[key].Image = Client.Properties.Resources.cross; but[key].Focus(); Field.test = new Deleg(Field.win_func); control(but[key].Tag, figure.id); }