public void Variations() { // ReSharper disable SuggestUseVarKeywordEvident // ReSharper disable RedundantDelegateCreation // Add a method group to the delegate - C# 1.0 var intDelegate = new IntDelegate(WriteMsg); // ReSharper restore RedundantDelegateCreation // ReSharper restore SuggestUseVarKeywordEvident // Add using implicit method group conversion - C# 2.0 // += polymorphic add, -= polymorphic remove intDelegate += WriteMsg; // ReSharper disable ConvertToLambdaExpression // Add as an anonymous method - C# 2.0 // += (args) => {statements} intDelegate += delegate(int i) { Console.WriteLine("msg: {0} (delegate via anonymous inline method)", i); }; _msgCount++; // ReSharper restore ConvertToLambdaExpression // Add as a lamba expression - C# 3.0 intDelegate += i => Console.WriteLine("msg: {0} (lamba)", i); _msgCount++; // results in 4 msgs intDelegate(123); Assert.Equal(4, _msgCount); }
public int EndAdd(IAsyncResult ar) { Trace("Service.EndAdd"); IntDelegate theDelegate = (IntDelegate)((System.Runtime.Remoting.Messaging.AsyncResult)ar).AsyncDelegate; return(theDelegate.EndInvoke(ar)); }
void UseDelegate(IntDelegate intDelegate) { IntDelegate intFromDelegate = intDelegate; int i = intFromDelegate(); Debug.Log("int from intDelegate: " + i); }
public static int Main() { Gen <ClassA> ga = new Gen <ClassA> (); IntDelegate id = ga.getIntDelegate(); TDelegate <ClassA> tda = ga.getTDelegate(); IntDelegate vid = ga.getVirtIntDelegate(); TDelegate <ClassA> stda = ga.getStaticTDelegate(); if (id(123) != 124) { return(1); } if (tda().GetType() != typeof(ClassA[])) { return(1); } if (vid(123) != 125) { return(1); } if (stda().GetType() != typeof(ClassA[])) { return(1); } tda = (TDelegate <ClassA>)Delegate.CreateDelegate(typeof(TDelegate <ClassA>), typeof(Gen <ClassA>).GetMethod("staticTFunction")); if (tda().GetType() != typeof(ClassA[])) { return(1); } return(0); }
public IAsyncResult BeginAdd(int x, int y, AsyncCallback callback, object state) { Trace("Service.BeginAdd"); IntDelegate theDelegate = new IntDelegate(this.AddDoWork); return(theDelegate.BeginInvoke(x, y, callback, state)); }
public static int Main () { var del = new IntDelegate (TestInt); del (a : 7); return 0; }
static void TransformUpTo(IntDelegate d, int max) { for (int i = 0; i <= max; i++) { Console.WriteLine(d(i)); } }
static void Main(string[] args) { sDelegate = StringCallback; TestClass testObj = new TestClass(); voidInstance = testObj.Func1; voidInstance(); voidInstance = testObj.Func2; voidInstance(); Console.WriteLine(); voidInstance += testObj.Func1; voidInstance += testObj.Func1; voidInstance += testObj.Func1; voidInstance += testObj.Func2; voidInstance(); int c = testObj.Add(3, 5); testObj.ReturnResultWithCallback("Video", "Game", sDelegate); intDelegate += testObj.Sub; intDelegate += testObj.Add; intDelegate += testObj.Sub; int result = intDelegate(10, 2); Console.WriteLine("c = " + c); Console.WriteLine("result = " + result); Console.ReadKey(); }
public void updateHistory(object source, EventArgs e) { delegatelog("updating posts...", Color.Gray); int inc = 0; foreach (Group group in groupList) { try { var tampGroup = group; intDelegate = new IntDelegate(changProgBar); progressBar1.Invoke(intDelegate, Convert.ToInt32((progressBar1.Maximum / groupList.Count) * inc)); group.updatePosts(); inc++; if (tampGroup.posts.Count - group.posts.Count > 0) { for (int i = 0; i < tampGroup.posts.Count - group.posts.Count; i++) { log("added post: " + group.posts.ElementAt(group.posts.Count - 1 - i).groupId + '_' + group.posts.ElementAt(group.posts.Count - 1 - i).id); } } } catch { } } intDelegate = new IntDelegate(changProgBar); progressBar1.Invoke(intDelegate, 0); delegatelog("Posts has updated", Color.Gray); updateListBox(); }
public DispatchNonConfiguredCallBenchmark() { _interfaceProxy = Substitute.For <IInterfaceWithSingleMethod>(); _abstractClassProxy = Substitute.For <AbstractClassWithSingleMethod>(); _classPartialProxy = Substitute.For <ClassWithSingleMethod>(); _intDelegateProxy = Substitute.For <IntDelegate>(); _voidDelegateProxy = Substitute.For <VoidDelegate>(); }
public static int Main() { var del = new IntDelegate(TestInt); del(a: 7); return(0); }
public static bool TriggerEvent(IntDelegate e, int arg) { if (e == null) { return(false); } e(arg); return(true); }
protected virtual void Awake() { m_spriteRenderer = GetComponentInChildren <SpriteRenderer>(); m_glowEffect = GetComponentInChildren <SpriteGlowEffect>(); m_collider = GetComponentInChildren <BoxCollider2D>(); IsCostAP = true; IsDeath = false; SkillHashes = new List <int>(); OnSortingOrderChanged += OnSortingOrderChangedEvent; }
public WebClient CopyFileWithProgressAsync(string source, string destination, IntDelegate progress = null, VoidDelegate completed = null) { var webClient = new WebClient(); FileCopyProgress = progress; FileCopyCompleted = completed; webClient.DownloadProgressChanged += DownloadProgress; webClient.DownloadFileCompleted += DownloadComplete; webClient.DownloadFileAsync(new Uri(source), destination); return(webClient); }
/* * WaveFileReader(string) - 2004 July 28 * A fairly standard constructor that opens a file using the filename supplied to it. */ public WaveFileShifter(string filenameOriginal, string filenameChanged, int shiftedMilieSeconds, SolutionDelegate solutionDeleg, IntDelegate setMaxDeleg, IntDelegate updateDeleg) { reader = new BinaryReader(new FileStream(filenameOriginal, FileMode.Open, FileAccess.Read, FileShare.Read)); writer = new BinaryWriter(new FileStream(filenameChanged, FileMode.Create, FileAccess.Write)); this.filenameOriginal = filenameOriginal; this.filenameChanged = filenameChanged; this.shiftedMilieSeconds = shiftedMilieSeconds; this.solutionDeleg = solutionDeleg; this.setMaxDeleg = setMaxDeleg; this.updateDeleg = updateDeleg; }
public int GetFirstFoundInt(IEnumerable <Model> propertyList, IntDelegate intFinder) { int tempInt = -1; foreach (Model entity in propertyList) { tempInt = intFinder(entity); return(tempInt); } return(tempInt); }
public List <int> Zip(List <int> la, List <int> lb, IntDelegate f) { Debug.Assert(la.Count == lb.Count); // assume same length lists List <int> result = new List <int>(); for (int i = 0; i < la.Count; i++) { result.Add(f(la[i], lb[i])); } return(result); }
/*the signature above means that IntDelegate type has been create which can hold references * to methods that return int value and take one int argument*/ static void Main(string[] args) { IntDelegate delegateInstance = new IntDelegate(Square); //create new instance of IntDelegate and attaching Square method delegateInstance += Double; //attaching another method to the invokation list for this instance of IntDelegate int results = delegateInstance(5); //creating new int variable and assiging results of delegateInstance Console.WriteLine("Results: {0}", results); //displaying results of delegateInstance(5) running; /*if a delegate returns a value, in case of multipe methods assigned to the delegate, * the delegate will return value from the last method in its invokation list*/ }
private void SafeSetHealthBar(int amount) { if (progressBar1.InvokeRequired) { var del = new IntDelegate(SafeSetHealthBar); progressBar1.Invoke(del, new object[] { amount }); } else { progressBar1.Value = amount; } }
static void Main(string[] args) { // Assign type Method1Delegate to variable delegate1 and point it to Method1. Method1Delegate delegate1 = Method1; delegate1(); // Assign type Method2Delegate to variable delegate2 and point it to Method2. Method2Delegate delegate2 = Method2; Console.WriteLine("Method 2 float value " + delegate2()); // Assign type Method3Delegate to variable delegate3 and point it to Method3. Method3Delegate delegate3 = Method3; delegate3("Andreas", 25, 1.82f); // Create a new instance of Math class. Math mathObject = new Math(); // Assign type MathDelegate to variable math and point it to Addition method in Math class. MathDelegate math = mathObject.Addition; Console.WriteLine("Addition 17 + 18 = " + math(17, 18)); // Assign math variable to Multiplication method in Math class. math = mathObject.Multiplication; Console.WriteLine("Multiplication 3 * 7 = " + math(3, 7)); // Assign type MyDelegate to variable myDelegate and point it to Method4. MyDelegate myDelegate = Method4; // Assign another method to myDelegate myDelegate += Method5; // Invoke myDelegate, it will call both Method4 and Method5. myDelegate(); // Assign type IntDelegate to variable addition and point it to Lambda Expression IntDelegate addition = (num1, num2) => num1 + num2; Console.WriteLine("Addition 13 + 4 = " + addition(13, 4)); // Assign type IntDelegate to variable subtraction and point it to Lambda Expression IntDelegate subtraction = (num1, num2) => num1 - num2; Console.WriteLine("Subtraction 8 - 2 = " + subtraction(8, 2)); // Assign type IntDelegate to variable subtraction and point it to Lambda Expression FloatDelegate multiplication = (num1, num2) => num1 * num2; Console.WriteLine("Multiplication 4.2 * 3.1 = " + multiplication(4.2f, 3.1f)); // Assign type IntDelegate to variable division and point it to Lambda Expression FloatDelegate division = (num1, num2) => num1 / num2; Console.WriteLine("Multiplication 4 / 32 = " + division(4, 32)); }
public void OnDestroy() { onSubmit = null; onHover = null; onClick = null; onToggleChanged = null; onDragStart = null; onDragEnd = null; onSliderChanged = null; onScrollbarChanged = null; onDrag = null; onDrapDownChanged = null; onInputFieldChanged = null; }
public static void PrintCollection(List <int> myList, IntDelegate even, IntDelegate odd) { foreach (var number in myList) { if (number % 2 == 0) { even(number); } else if (number % 2 != 0) { odd(number); } } }
static void Main(string[] args) { //Console.WriteLine("Hello World!"); MyDelegate del = ClassA.MethodA; del("Hello"); del = ClassB.MethodB; del("World"); del = (string msg) => Console.WriteLine("Called ambda expression: " + msg); del("Hello World"); del = ClassA.MethodA; InvokeDelegate(del); del = ClassB.MethodB; InvokeDelegate(del); del = (string msg) => Console.WriteLine("Called lambda expression: " + msg); InvokeDelegate(del); MyDelegate del1 = ClassA.MethodA; MyDelegate del2 = ClassB.MethodB; del = del1 + del2; del("Combined Delegate: Hello World"); MyDelegate del3 = (string msg) => Console.WriteLine("Called lambda expression: " + msg); del += del3; del("Combined with del3 Hello World"); IntDelegate del4 = ClassA.MethodA; IntDelegate del5 = ClassB.MethodB; del4 += del5; Console.WriteLine(del4()); //return ClassB.MethodB add <int> sum = Sum; Console.WriteLine(sum(10, 20)); add <string> concat = Concat; Console.WriteLine(concat("Hello ", "World ")); }
public void GetILGenerator_Int_Owner(bool skipVisibility) { IDClass target = new IDClass(); FieldInfo field = typeof(IDClass).GetField(FieldName, BindingFlags.Instance | BindingFlags.NonPublic); Type[] paramTypes = new Type[] { typeof(IDClass), typeof(int) }; DynamicMethod method = new DynamicMethod("Method", typeof(int), paramTypes, typeof(IDClass), skipVisibility); ILGenerator ilGenerator = method.GetILGenerator(8); Helpers.EmitMethodBody(ilGenerator, field); IntDelegate instanceCallBack = (IntDelegate)method.CreateDelegate(typeof(IntDelegate), target); VerifyILGenerator(instanceCallBack, target, 0); }
public void CreateDelegate_Target_Type(IDClass target) { int newId = 0; FieldInfo field = typeof(IDClass).GetField(FieldName, BindingFlags.NonPublic | BindingFlags.Instance); DynamicMethod method = new DynamicMethod("Method", typeof(int), new Type[] { typeof(IDClass), typeof(int) }, typeof(IDClass)); ILGenerator ilGenerator = method.GetILGenerator(); Helpers.EmitMethodBody(ilGenerator, field); IntDelegate instanceCallBack = (IntDelegate)method.CreateDelegate(typeof(IntDelegate), target); Assert.Equal(instanceCallBack(newId), target.ID); Assert.Equal(newId, target.ID); }
static void Main(string[] args) { MultiCastDelegate MCD = new MultiCastDelegate(); MYDelegate m = new MYDelegate(MCD.Hello1); m += MCD.Hello2; m.Invoke(); MultiCastDelegate2 mcd2 = new MultiCastDelegate2(); IntDelegate IDel = new IntDelegate(mcd2.add); IDel += mcd2.sub; IDel += mcd2.div; IDel.Invoke(100, 200); Console.WriteLine(); }
public void MainTest() { IntDelegate function = (int x, int y) => x * y; var result = function(123, 456); Console.WriteLine(result); Func <int, int, int> tmpFunc = (int x, int y) => { var t = x + y; return(t + x); }; result = tmpFunc(1, 2); Console.WriteLine(result); Action <int, int> tmpAction = (int x, int y) => { Console.WriteLine(x + y); }; tmpAction(33, 44); }
static void Main(string[] args) { DelegatePointsTo delegate1 = new DelegatePointsTo(Hello); delegate1("Hello, calling Hello()"); DelegatePointsTo delegate2 = new DelegatePointsTo(Pozdrav); delegate2("Now calling Pozdrav()"); DelegatePointsTo delegate12 = delegate1 + delegate2; delegate12("1-2"); IntDelegate intDel = new IntDelegate(RerturnInt); int var = intDel(123); Console.WriteLine(var); }
public VerifyReceivedCallBenchmark() { _interfaceProxy = Substitute.For <IInterfaceWithSingleMethod>(); _interfaceProxy.IntMethod("42"); _interfaceProxy.VoidMethod("42"); _abstractClassProxy = Substitute.For <AbstractClassWithSingleMethod>(); _abstractClassProxy.IntMethod("42"); _abstractClassProxy.VoidMethod("42"); _classPartialProxy = Substitute.For <ClassWithSingleMethod>(); _classPartialProxy.IntMethod("42"); _classPartialProxy.VoidMethod("42"); _intDelegateProxy = Substitute.For <IntDelegate>(); _intDelegateProxy("42"); _voidDelegateProxy = Substitute.For <VoidDelegate>(); _voidDelegateProxy("42"); }
public DispatchConfiguredMatchingCallBenchmark() { _interfaceProxy = Substitute.For <IInterfaceWithSingleMethod>(); _interfaceProxy.IntMethod("42").Returns(42); _interfaceProxy.When(x => x.VoidMethod("42")).Do(delegate { }); _abstractClassProxy = Substitute.For <AbstractClassWithSingleMethod>(); _abstractClassProxy.IntMethod("42").Returns(42); _abstractClassProxy.When(x => x.VoidMethod("42")).Do(delegate { }); _classPartialProxy = Substitute.For <ClassWithSingleMethod>(); _classPartialProxy.IntMethod("42").Returns(42); _classPartialProxy.When(x => x.VoidMethod("42")).Do(delegate { }); _intDelegateProxy = Substitute.For <IntDelegate>(); _intDelegateProxy.Invoke("42").Returns(42); _voidDelegateProxy = Substitute.For <VoidDelegate>(); _voidDelegateProxy.When(x => x.Invoke("42")).Do(delegate { }); }
// create a static method that: // takes an Integer // return the double Value /* * create a static method that: * takes a string * returns that string in uppercase */ static void Main(string[] args) { VoidDelegate vd = new VoidDelegate(StaticMethodVoid); IntDelegate id = new IntDelegate(StaticMethodInt); StringDelegate sd = new StringDelegate(StaticMethodString); VoidDelegate vd2 = new VoidDelegate(SecondVoidStaticMethod); vd(); vd2(); Console.WriteLine("The value of {0} double is {1}", 5, id(5)); string text = "My string text"; Console.WriteLine("{0} in uppercase is {1}", text, sd(text)); foreach (char c in text) { Console.WriteLine("{0} in ASCII2 is {1}", c, (int)c); } Console.ReadKey(); }
IEnumerable <object> MyEnum() { int stateFullVar = 101; int stateFullVar_DelegRef = 102; int stateFullVar_NestedDelegRef = 103; yield return(stateFullVar + stateFullVar_DelegRef + stateFullVar_NestedDelegRef); { int stateLessVar = 201; int stateLessVar_DelegRef = 202; int stateLessVar_NestedDelegRef = 203; System.Diagnostics.Debugger.Break(); IntDelegate deleg = delegate(int delegArg_NestedDelegRef) { int delegVar = 301; int delegVar_NestedDelegRef = 302; Console.WriteLine(stateFullVar_DelegRef); Console.WriteLine(stateLessVar_DelegRef); IntDelegate nestedDeleg = delegate(int nestedDelegArg) { int nestedDelegVar = 303; Console.WriteLine(delegArg_NestedDelegRef); Console.WriteLine(delegVar_NestedDelegRef); Console.WriteLine(stateFullVar_NestedDelegRef); Console.WriteLine(stateLessVar_NestedDelegRef); Console.WriteLine(this); System.Diagnostics.Debugger.Break(); }; System.Diagnostics.Debugger.Break(); nestedDeleg(402); }; deleg(401); } }
public static void ShowResult(int a, int b, IntDelegate del) { Console.WriteLine(del(a, b)); }
public IAsyncResult BeginAdd(int x, int y, AsyncCallback callback, object state) { Trace("Service.BeginAdd"); IntDelegate theDelegate = new IntDelegate(this.AddDoWork); return theDelegate.BeginInvoke(x, y, callback, state); }
public static void Main () { var del = new IntDelegate (TestInt); del (b : 7); }
public KeyAssignment(Keys key, IntDelegate function, int hotkey) { mKey = key; mDelegate = function; mToggle = true; mArgs = hotkey; }
private void VerifyILGenerator(IntDelegate instanceCallBack, IDClass target, int newId) { Assert.Equal(instanceCallBack(newId), target.ID); Assert.Equal(newId, target.ID); }
public frmDownloader(string urldownload,string urlstore,bool top) { try { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // //this.fileNameChanger = new StringDelegate(this.ChangeFileName); this.statusChanger = new StringDelegate(this.ChangeStatus); this.singlePercentChanger = new IntDelegate(this.ChangeSinglePercent); //this.totalPercentChanger = new IntDelegate(this.ChangeTotalPercent); //this.activeStateChanger = new BoolsDelegate(this.ChangeActiveState); //initialize the urls settings. this.strurldownload=urldownload; this.strurlStore=urlstore; this.TopMost=true; this.ShowInTaskbar=false; this.chkDwndCompl.Checked=true; this.chkDwndCompl.Enabled=false; this.btnCancel.Enabled =false; } catch(Exception exp) { WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Managecontents==>frmDownloader.cs 178",exp,null,false); } }
public static void Main () { var del = new IntDelegate (TestInt); del.DynamicInvoke (b : 7); }