method-invocation

Handle Generic methods in a dictionary according to type

落花浮王杯 提交于 2021-02-07 18:27:26
问题 I have a generic method public delegate void Handler<T>(T val); I enable users to register to events and provide this delegate. I need to save the list of delegate according to their types. I tried saving in a dictionary of Type and object. when adding the method I cast it to a List<Handler<T>> according to the T. but then when an event occurred I do not have the T so cannot cast to the relevant list of generic handlers (I do have the Type but not the T) I solved this by saving methodInfo

Powershell function call changing passed string into int

跟風遠走 提交于 2021-01-05 08:58:46
问题 So I am using the kind of buggy Sapien powershell studio to make a powershell driven GUI application, and I am attempting to perform an ADSI query. $nameOfDeviceInput is a System.Windows.Forms.TextBox On one form, I have the following function: $buttonPerformAction_Click={ if (FindInAD($nameOfDeviceInput.Text).Count -gt 0) { $buttonPerformAction.BackColor = 'Red' $buttonPerformAction.Text = "System already exists in AD with that name. Try another name" return } ..... } On the "main" form, I

Understanding the Dispatcher Queue

时光怂恿深爱的人放手 提交于 2020-01-22 07:08:32
问题 I think I need some help understanding the Dispatcher Queue . When new work arrives it gets added at the beginning of the dispatcher queue and when the Dispatcher wants to process a working item it gets removed from the beginning. In more general terms: If there is work it gets stored in a FIFO manner inside the queue and processed as long there is no work left. The MSDN documentation here is referring to a loop and a frame : The Dispatcher processes the work item queue in a loop. The loop is

Why calling this function recursively does not throw a NullPointerException

我们两清 提交于 2020-01-15 06:42:07
问题 My question comes from this thread. Consider this code: public class Test { static Function<Integer, Integer> fibLambda = null; public static void main (String[] args) { fibLambda = n -> n <= 2 ? 1 : fibLambda.apply(n - 1) + fibLambda.apply(n - 2); System.out.println(fibLambda.apply(6)); } } The output above is 8. What I don't get is that how fibLamdba is initialized? It seems that I totally miss how the method invocation is done because I though that this code would produce a NPE. Hope my

A better way to write extension method to invoke a control?

女生的网名这么多〃 提交于 2020-01-13 18:14:31
问题 I have this general function to invoke a WinForm control: public static void Invoke(this Control c, Action action) { if (c.InvokeRequired) c.TopLevelControl.Invoke(action); else action(); } I'm thinking of making it better by bringing harsher constraints to prevent things that are meaningless, may be like: button1.Invoke(() => list.Add(1)); Also there can be redundant typing like: button1.Invoke(() => button1.Hide()); since we are already specifying the this is button1 . So I made it: public

Scala: How can I create a function that allows me to use dot notation when calling it?

a 夏天 提交于 2019-12-21 19:49:08
问题 I have been confused about this for a while, even despite reading the Scala Style Guide - Method Invocation several times. I want to be able to call this method def foldRVL[A,B](l: List[A], z: B)(f: (A, B) => B) = //"Right-Via-Left" l.reverse.foldLeft(z)((a, b) => f(b, a)) using dot notation like this List(1,2,3).foldRVL(0)(_ + _) . And not like this: foldRVL(List(1,2,3), 0)(_ + _) . Also, sometimes I've seen code that shows methods that actually either takes zero parameters in their

Invoke method with an array parameter using reflection

人盡茶涼 提交于 2019-12-19 12:52:31
问题 I am attempting to write a method the executes a static method from another class by passing an array of strings as arguments to the method. Here's what I have: public static void executeStaticCommand(final String[] command, Class<?> provider) { Method[] validMethods = provider.getMethods(); String javaCommand = TextFormat.toCamelCase(command[0]); for (Method method : validMethods) { if (method.getName().equals(javaCommand)) { try { method.invoke(null, new Object[] { new Object[] { command }

How to suspend a java thread for a small period of time, like 100 nanoseconds?

余生颓废 提交于 2019-12-17 18:50:13
问题 I know Thread.sleep() can make a java thread suspend for a while, like certain milliseconds and certain nanoseconds. But the problem is the invocation of this function also causes overhead. For example, if I want a thread to suspend for 100 nanoseconds, and I call Thread.sleep(0, 100) . The whole cost for this process is invocation_cost + 100 nanosceonds , which may be much larger the what I want. How could I avoid this problem, and achieve my purpose? The reason I need this is that I want to

Why is ** optional when “splatting” keyword arguments?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 11:47:32
问题 Given this method definition: def foo(a = nil, b: nil) p a: a, b: b end When I invoke the method with a single hash argument, the hash is always implicitly converted to keyword arguments, regardless of ** : hash = {b: 1} foo(hash) #=> {:a=>nil, :b=>1} foo(**hash) #=> {:a=>nil, :b=>1} I can pass another (empty) hash as a workaround: foo(hash, {}) #=> {:a=>{:b=>1}, :b=>nil} But , this looks pretty cumbersome and awkward. I would have expected Ruby to handle this more like arrays are handled, i

Bean properties not being updated

点点圈 提交于 2019-12-12 02:29:25
问题 My bean is viewscoped. I have a simple string property with a getter and setter. The getter works fine(checked by initialising the property), but not the setter. In the setter method I am building a Stringbuffer using each of the incoming parameter. Code: public String getParamval() { return paramval; } public void setParamval(String paramval) { logger.info("Incoming value:" + paramval); pvals.append(paramval); this.paramval = "VAL"; } Is that wrong? I have tested within the setter to see if