delegates

How do I make a generic delegate using a type in C#?

江枫思渺然 提交于 2021-01-28 05:11:12
问题 If I have a type, like: Type type = myObject.GetType (); How do I make a generic delegate that uses objects of that that type as a parameter? I would expect code something like: myDelegate = Action<type> (type parameter); The above code obviously won't and doesn't work as is, but how can I make it work? Can I even make it work? Ultimately, I have a dictionary of Dictionary < Type, List < Action < > >, which holds a type and a list of delegates that should take an object of that type as

Ruby: DRY class methods calling Singleton instance methods [duplicate]

时光总嘲笑我的痴心妄想 提交于 2021-01-27 08:44:55
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include

Ruby: DRY class methods calling Singleton instance methods [duplicate]

时间秒杀一切 提交于 2021-01-27 08:44:49
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include

Ruby: DRY class methods calling Singleton instance methods [duplicate]

ぐ巨炮叔叔 提交于 2021-01-27 08:43:34
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include

Ruby: DRY class methods calling Singleton instance methods [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 08:43:34
问题 This question already has answers here : Calling a method of a Ruby Singleton without the reference of 'instance' (5 answers) Closed 5 years ago . I have the a Singleton class ExchangeRegistry which keeps all the Exchange objects. Instead of needing to call: ExchangeRegistry.instance.exchanges I want to be able to use: ExchangeRegistry.exchanges This works, but I'm not happy with the repetition: require 'singleton' # Ensure an Exchange is only created once class ExchangeRegistry include

public Event in abstract class

陌路散爱 提交于 2021-01-27 03:53:35
问题 I have event declared in abstract class: public abstract class AbstractClass { public event Action ActionEvent; } public class MyClass : AbstractClass { private void SomeMethod() { //Want to access ActionEvent-- Not able to do so if (ActionEvent != null) { } } } I wanted to access this base class event in derived. Further I wanted to access this event in some other derived class of MyClass: MyClass.ActionEvent += DerivedMethod() Please help me understand how to work with event defined in

public Event in abstract class

本小妞迷上赌 提交于 2021-01-27 03:53:25
问题 I have event declared in abstract class: public abstract class AbstractClass { public event Action ActionEvent; } public class MyClass : AbstractClass { private void SomeMethod() { //Want to access ActionEvent-- Not able to do so if (ActionEvent != null) { } } } I wanted to access this base class event in derived. Further I wanted to access this event in some other derived class of MyClass: MyClass.ActionEvent += DerivedMethod() Please help me understand how to work with event defined in

public Event in abstract class

余生颓废 提交于 2021-01-27 03:53:25
问题 I have event declared in abstract class: public abstract class AbstractClass { public event Action ActionEvent; } public class MyClass : AbstractClass { private void SomeMethod() { //Want to access ActionEvent-- Not able to do so if (ActionEvent != null) { } } } I wanted to access this base class event in derived. Further I wanted to access this event in some other derived class of MyClass: MyClass.ActionEvent += DerivedMethod() Please help me understand how to work with event defined in

How to pass function pointer from C# to a C++ Dll?

杀马特。学长 韩版系。学妹 提交于 2021-01-21 07:59:44
问题 The function defined in C++ dll is: static double (*Func1)(double); EXTERN_C __declspec(dllexport) __stdcall double TestDelegate(double (*fun)(double)) { Func1 = fun; return Func1(25.0); } void My_Real_purpose() { SomeClass a; a.SetFunction(Func1);//Define behaviour of a by C# in runtime a.DoSomething();//Even I want it runs in another thread! } And I tried to call it in C# like this: class A { [DllImport("DllName.dll")] public extern static double TestDelegate(IntPtr f); public delegate

How to pass function pointer from C# to a C++ Dll?

a 夏天 提交于 2021-01-21 07:58:25
问题 The function defined in C++ dll is: static double (*Func1)(double); EXTERN_C __declspec(dllexport) __stdcall double TestDelegate(double (*fun)(double)) { Func1 = fun; return Func1(25.0); } void My_Real_purpose() { SomeClass a; a.SetFunction(Func1);//Define behaviour of a by C# in runtime a.DoSomething();//Even I want it runs in another thread! } And I tried to call it in C# like this: class A { [DllImport("DllName.dll")] public extern static double TestDelegate(IntPtr f); public delegate