delegates

Delegates and variables scope

ぐ巨炮叔叔 提交于 2021-02-07 08:19:04
问题 I have the following code: public void SetMove(Position3D pos, float time, float linearity, bool relative) { ExecuteOnActiveClients(delegate(NeuroClient client) { client.Engine.GetProcAnimation(name).SetMove(pos, time, linearity, relative); }, true, true); } Where ExecuteOnActiveClients pushes the delegate in a queue, consumed asynchronously, and has the following signature: void ExecuteOnActiveClients(ClientDelegate action, Boolean parallel, Boolean wait, Boolean lockClient) I have a lot of

Delegates and variables scope

牧云@^-^@ 提交于 2021-02-07 08:18:30
问题 I have the following code: public void SetMove(Position3D pos, float time, float linearity, bool relative) { ExecuteOnActiveClients(delegate(NeuroClient client) { client.Engine.GetProcAnimation(name).SetMove(pos, time, linearity, relative); }, true, true); } Where ExecuteOnActiveClients pushes the delegate in a queue, consumed asynchronously, and has the following signature: void ExecuteOnActiveClients(ClientDelegate action, Boolean parallel, Boolean wait, Boolean lockClient) I have a lot of

Understanding delegates and Events in C# using a specific example

China☆狼群 提交于 2021-02-07 03:57:03
问题 So I'm at the point of understanding events and delegates. I overally understand the usage of delegates. The only thing that concerns me about delegates is whether a delegate can be configured to work with functions that are not related to events in any way... if yes, how do I write the logic for a delegate-defined function? (I guess such function doesn't really have much of a point to it, but it's good to know.) As for events... I'm having a hard time understanding it. I get the idea that an

Understanding delegates and Events in C# using a specific example

北战南征 提交于 2021-02-07 03:50:37
问题 So I'm at the point of understanding events and delegates. I overally understand the usage of delegates. The only thing that concerns me about delegates is whether a delegate can be configured to work with functions that are not related to events in any way... if yes, how do I write the logic for a delegate-defined function? (I guess such function doesn't really have much of a point to it, but it's good to know.) As for events... I'm having a hard time understanding it. I get the idea that an

Understanding delegates and Events in C# using a specific example

跟風遠走 提交于 2021-02-07 03:46:56
问题 So I'm at the point of understanding events and delegates. I overally understand the usage of delegates. The only thing that concerns me about delegates is whether a delegate can be configured to work with functions that are not related to events in any way... if yes, how do I write the logic for a delegate-defined function? (I guess such function doesn't really have much of a point to it, but it's good to know.) As for events... I'm having a hard time understanding it. I get the idea that an

Create generic Func from reflection

ε祈祈猫儿з 提交于 2021-02-06 12:49:15
问题 I've specified type in a variable: Type hiddenType . I need to create a Func<T> delegate where T is of type specified in mentioned variable and assign an method: var funcType = typeof(Func<>).MakeGenericType(hiddenType); Func<object> funcImplementation = () => GetInstance(hiddenType); var myFunc= Delegate.CreateDelegate(funcType , valueGenerator.Method); It doesn't works - because funcImplementation is returns object instead of desired. At runtime, it will surely be an instance of type

Create generic Func from reflection

Deadly 提交于 2021-02-06 12:46:56
问题 I've specified type in a variable: Type hiddenType . I need to create a Func<T> delegate where T is of type specified in mentioned variable and assign an method: var funcType = typeof(Func<>).MakeGenericType(hiddenType); Func<object> funcImplementation = () => GetInstance(hiddenType); var myFunc= Delegate.CreateDelegate(funcType , valueGenerator.Method); It doesn't works - because funcImplementation is returns object instead of desired. At runtime, it will surely be an instance of type

How can I chain methods depending on user input?

我的未来我决定 提交于 2021-02-05 09:36:16
问题 I have a method that I'm using to process images (rotate, filter, resize, etc). It looks like this: public Image ProcessImage(Image image, Func<ImageFactory, ImageFactory> process) { using (var imageFactory = new ImageFactory(preserveExifData: true)) { using (var imageStream = new MemoryStream()) { var loadResult = imageFactory.Load(image); var processResult = process(loadResult); processResult.Save(imageStream); return Image.FromStream(imageStream); } } } Since I'm using Func<> in this way I

How to pass a parameter to another class using events

烂漫一生 提交于 2021-02-05 08:23:25
问题 I have a usercontrol which is having one button Usercontrolclass.cs Button click event private void btn_OK_Click(object sender, EventArgs e) { value= Convert.ToDouble(txt_ActualValue.Text); if(getvalue!=null) getvalue(null, new EventArga()); } private variable private int value; property: public double finalvalue { get { return value; } } MainForm.cs I'm using that Usercontrol into this mainform I need to get the value from this class in constructor: Usercontrolclass.getvalue+

Raise event c# gives error: No overload matches delegate EventHandler

时光总嘲笑我的痴心妄想 提交于 2021-01-29 19:04:13
问题 I am trying to make an event that gets raised when something happens. So other classes that contain a reference to the class that raised the event get notified. This is what i have got so far: using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class DropArea : MonoBehaviour { public event EventHandler ObjectChange; void Start () { } // Update is called once per frame void Update () { } void OnTriggerEnter(Collider other) { var correctType =