delegates

Creating delegates dynamically with parameter names

最后都变了- 提交于 2019-12-28 06:15:29
问题 Hi I'm trying to create a function that dynamically creates a delegate with the same return value and the same parameters as a MethodInfo it receives as parameter and also and this is very important the same parameter names! What I did so far is create a function that returns a lambda that receives the same parameter types and has the same return value as the MethodInfo but it doesn't have the parameter names: static void Example() { Person adam = new Person(); MethodInfo method = typeof

Creating delegates dynamically with parameter names

南楼画角 提交于 2019-12-28 06:15:08
问题 Hi I'm trying to create a function that dynamically creates a delegate with the same return value and the same parameters as a MethodInfo it receives as parameter and also and this is very important the same parameter names! What I did so far is create a function that returns a lambda that receives the same parameter types and has the same return value as the MethodInfo but it doesn't have the parameter names: static void Example() { Person adam = new Person(); MethodInfo method = typeof

Pass and execute delegate in separate AppDomain

試著忘記壹切 提交于 2019-12-28 04:50:08
问题 I want to exceute some piece of code in separate AppDomain with delegate. How can I do this? UPD1 : some more details about my problem My program processing some data (one iteration is: get some data from DB, evaluate it and create assemblies at runtime, execute dynamic assemblies and write results to DB). Current solution: each iteration running in separate thread. Better solution: each iteration running in separate AppDomain (to unload dynamic asseblies). UPD2 : All, thanks for answers. I

Eclipse gets stuck when trying to launch Android app

让人想犯罪 __ 提交于 2019-12-28 03:31:10
问题 I'm trying to run helloandroid application on a Motorola Milestone A853. I typed "adb devices" and the mobile is properly recognized. However, when I try to run the application Eclipse always stuck at 27% "Launching delegate". Which could be the reason? 回答1: Had the same 27% problem with an emulator. It only got fixed after I deleted the AVD and recreated it, so this is very likely device/emulator related (and furthermore restarting the ADB did not fix the problem). EDIT: Found this over at

Why doesn't the C# ternary operator work with delegates?

 ̄綄美尐妖づ 提交于 2019-12-28 03:04:45
问题 When branching to select a function, it might make sense to use the ternary operator to select a function, but this is impossible. Why? public class Demo { protected bool branch; protected void demo1 () {} protected void demo2 () {} public Action DoesntWork() { return branch ? demo1 : demo2; } } The compiler produces the following error: Cannot implicitly convert type `method group' to `System.Action' 回答1: The problem is that demo1 is not a simple expression, it is a method . And methods can

Delegates, Why? [duplicate]

醉酒当歌 提交于 2019-12-28 01:43:08
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: When would you use delegates in C#? The purpose of delegates I have seen many question regarding the use of delegates. I am still not clear where and WHY would you use delegates instead of calling the method directly. I have heard this phrase many times: "The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked." I

Equivalent of C# anonymous methods in Java?

霸气de小男生 提交于 2019-12-27 22:09:24
问题 In C# you can define delegates anonymously (even though they are nothing more than syntactic sugar). For example, I can do this: public string DoSomething(Func<string, string> someDelegate) { // Do something involving someDelegate(string s) } DoSomething(delegate(string s){ return s += "asd"; }); DoSomething(delegate(string s){ return s.Reverse(); }); Is it possible to pass code like this in Java? I'm using the processing framework, which has a quite old version of Java (it doesn't have

Is it possible to have a delegate as attribute parameter?

江枫思渺然 提交于 2019-12-27 17:32:46
问题 Is it possible to have a delegate as the parameter of an attribute? Like this: public delegate IPropertySet ConnectionPropertiesDelegate(); public static class TestDelegate { public static IPropertySet GetConnection() { return new PropertySetClass(); } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface,AllowMultiple=false,Inherited=true)] public class WorkspaceAttribute : Attribute { public ConnectionPropertiesDelegate ConnectionDelegate { get; set; } public

Is it possible to have a delegate as attribute parameter?

Deadly 提交于 2019-12-27 17:32:14
问题 Is it possible to have a delegate as the parameter of an attribute? Like this: public delegate IPropertySet ConnectionPropertiesDelegate(); public static class TestDelegate { public static IPropertySet GetConnection() { return new PropertySetClass(); } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface,AllowMultiple=false,Inherited=true)] public class WorkspaceAttribute : Attribute { public ConnectionPropertiesDelegate ConnectionDelegate { get; set; } public

Is EndInvoke() optional, sort-of optional, or definitely not optional?

为君一笑 提交于 2019-12-27 11:55:29
问题 I've read conflicting opinions as to whether every BeginInvoke() has to be matched by an EndInvoke(). Are there any leaks or other problems associated with NOT calling EndInvoke()? 回答1: Delegate.EndInvoke is documented as a thou shalt call this (i.e. necessary - else leaks happen) - from msdn: Important Note No matter which technique you use, always call EndInvoke to complete your asynchronous call. Control.EndInvoke is OK to ignore for fire-and-forget methods - from msdn: You can call