invoke

C# how to invoke a field initializer using reflection?

孤者浪人 提交于 2019-12-23 16:33:40
问题 Say I have this C# class public class MyClass { int a; int[] b = new int[6]; } Now say I discover this class using reflection and while looking at the fields I find that one of them is of type Array (ie: b) foreach( FieldInfo fieldinfo in classType.GetFields() ) { if( fieldInfo.FieldType.IsArray ) { int arraySize = ?; ... } } I know it's not guaranteed that the array has a field initializer that creates the array but if it does I would like to know the size of the array created by the field

Dynamically load a Class and invoke a method in Java

有些话、适合烂在心里 提交于 2019-12-23 13:06:52
问题 Lets say i want to dynamically load a class in java and call it's start() (has no params) method: Class<?> c = Class.forName("AbuseMe"); c.getMethod("start").invoke(c.newInstance()); Would this be a good/safe way to do it? 回答1: Looks good to me. If you're doing a lot of reflection-related code you might look at Apache Beanutils or Apache OGNL or something similar. 回答2: Reflection is a very useful approach to deal with the Java class at runtime, it can be use to load the Java class, call its

updating UI thread using BackGroundWorker in C# Form application

匆匆过客 提交于 2019-12-23 05:32:33
问题 I have a time consuming task that tests a couple of network connections. In my example below I have confined it to one connection. Normally the connection returns quickly but it could happen that the connection cannot be made so that the socket times out. During this time I would like to display an "idler" gif in the Form, when the connection succeeds the app should change the Image in the Form to some green check icon or in case of a failing connection a red icon "stopper" should be

C# - automatic delegate type from method

家住魔仙堡 提交于 2019-12-22 10:27:50
问题 Any way to avoid explicitly declaring MyMethodDelegate in a scenario like this? bool MyMethod(string x) { //... } BeginInvoke(new MyMethodDelegate(MyMethod), x); I know about lambdas a-la ()=>MyMethod(x) , however I want to avoid them sometimes as they break edit-and-continue. Edit : just BeginInvoke(MyMethod, x) does not work: The best overloaded method match for 'System.Windows.Forms.Control.BeginInvoke(System.Delegate, params object[])' has some invalid arguments Argument 1: cannot convert

Control.Invoke getting 'stuck' in hidden ShowDialog

佐手、 提交于 2019-12-22 09:01:11
问题 (I have a workaround for this problem, but it's not the first time I've been bitten, so I'm trying to understand exactly what's going on.) From my application, I ShowDialog a form. On the form is a button, which when clicked calls code on another (non-Gui) thread. The non-GUI thread sends back statuses ( Pushed then Released ) via a Control.Invoke When the form sees the Pushed , it invokes form.Hide() When the form sees the Released , it changes the appearance of the button. What happens is

A threading problem where mono hangs and MS.Net doesn't

最后都变了- 提交于 2019-12-22 04:53:05
问题 I'm testing my app with mono in prevision of a Linux port, and I have a threading problem. I initially considered pasting 3000 code lines here, but finally I've devised a small minimal example ;) You have a form with a button (poetically named Button1 , and a label (which bears, without surprise, the name Label1 )). The whole lot is living a happy life on a form called Form1 . Clicking Button1 launches an infinite loop that increments a local counter and updates Label1 (using Invoke ) to

PowerShell Pass Named parameters to ArgumentList

*爱你&永不变心* 提交于 2019-12-22 03:43:36
问题 I have a PowerShell script that accepts 3 named parameters. Please let me know how to pass the same from command line. I tried below code but same is not working. It assigns the entire value to P3 only. My requirement is that P1 should contain 1, P2 should 2 and P3 should be assigned 3. Invoke-Command -ComputerName server -FilePath "D:\test.ps1" -ArgumentList {-P1 1 -P2 2 -P3 3} Ihe below is script file code. Param ( [string]$P3, [string]$P2, [string]$P1 ) Write-Output "P1 Value :" $P1 Write

ESB MULE passing the parameters to the java method

﹥>﹥吖頭↗ 提交于 2019-12-21 21:26:58
问题 I use MULE version 3.3.0 CE, I want to get some value from header in inbound and then pass it to a java method, in java method making some changes on passed value, finally again I pass it from java method to the outbound???? 回答1: Instead of tying your Java beans to the Mule API (with Callable ), you can do this using MEL only, for example with: <invoke object-ref="yourBean" method="yourMethod" methodArguments="#[message.inboundProperties['inboundPropertyName']]" /> <set-property propertyName=

return value from control.Invoke((MethodInvoker) delegate { /* … */ }; I need some explanations

夙愿已清 提交于 2019-12-21 20:47:30
问题 What's the difference between #1 and #2: Code 1 (compiled ok): byte[] GetSomeBytes() { return (byte[])this.Invoke((MethodInvoker)delegate { GetBytes(); }); } byte[] GetBytes() { GetBytesForm gbf = new GetBytesForm(); if(gbf.ShowDialog() == DialogResult.OK) { return gbf.Bytes; } else return null; } Code 2 (didn't complied ok) int GetCount() { return (int)this.Invoke((MethodInvoker)delegate { return 3; }); } Code #2 gives me Since 'System.Windows.Forms.MethodInvoker' returns void, a return

Can I pass path parameters using lambda invoke to another lambda function?

血红的双手。 提交于 2019-12-21 20:06:22
问题 I'm trying to call and get the response from another lambda function using lambda invoke. The problem is other lambda function needs the id to be sent as path parameters (or as a query string). But I do not see an option in lambda invoke for this. If I pass the id in payload the other function will receive it in the event body and not as path parameters. Is there an existing solution for this? Here is a function inside a lambda function which calls another lambda function which receives the