invoke

“Object does not match target type” when calling methods using string in C#

こ雲淡風輕ζ 提交于 2019-11-29 15:30:48
I'm trying to call a method using a string, but there a problem: void make_moviment(string mov,Vector3 new_mov){ GameObject past_panel = GameObject.Find(actual_level.ToString()); Type t = Type.GetType(past_panel.GetComponents<MonoBehaviour>()[0].GetType ().Name); MethodInfo method = t.GetMethod("get_answer"); method.Invoke(t,new object[] { mov })); <--- PROBLEM HERE } There's always this error "Object does not match target type" related with the last line. Do you have any recommendations? method.Invoke(t,new object[] { mov })); Is the same as calling t.WhateverTheMethodIs(mov); But t is the

How to return a value with Dispatcher.Invoke?

孤人 提交于 2019-11-29 13:07:19
Anyone knows how to return a value from Dispatcher . Invoke in wpf ? I want to return the selected index for a ComboBox . Thanks! user216652 There's another way that returns value from Invoke(): object oIsLoaded = container.Dispatcher.Invoke( new Func<bool> ( () => { return container.IsLoaded; }) ); And by the way, chances are that the initial code (which is working with delegate) won't modify oIsLoaded at all; So I'd rather use a Func<> for returning a value from that kind of function. int result = -1; // this is synchronous myCombo.Invoke(() => { result = myCombo.SelectedIndex; }); return

How to invoke a method which throws an Exception using Java Reflection?

被刻印的时光 ゝ 提交于 2019-11-29 12:03:28
问题 I would like to invoke a method, using Java Reflection. The problem is that this method (which I wrote) throws an Exception (I created a myCustomException ). When I add a try/catch clause, I can't run my project, because Eclipse says "the catch clause is unreachable". Here is when I try to invoke myMethod in the class MyClass : 270. myMethod.invoke(null, myParam); // NB : null because myMethod is static When myMethod does not throw a MyCustomException , eveything is fine. But when it throws a

How to “invoke” a class instance in PHP?

£可爱£侵袭症+ 提交于 2019-11-29 10:23:56
is there any possibility to "invoke" a class instance by a string representation? In this case i would expect code to look like this: class MyClass { public $attribute; } $obj = getInstanceOf( "MyClass"); //$obj is now an instance of MyClass $obj->attribute = "Hello World"; I think this must be possible, as PHP's SoapClient accepts a list of classMappings which is used to map a WSDL element to a PHP Class. But how is the SoapClient "invoking" the class instances? $class = 'MyClass'; $instance = new $class; However, if your class' constructor accepts a variable number of arguments, and you hold

WPF invoke a control

落爺英雄遲暮 提交于 2019-11-29 09:24:31
How can I invoke a control with parameters? I've googled this up, but nowhere to find! invoke ui thread This is the error i get: Additional information: Parameter count mismatch. And this happens when i do a simple check whether the text property of a textbox control is empty or not. This works in WinForms: if (this.textboxlink.Text == string.Empty) SleepThreadThatIsntNavigating(5000); It jumps from this if the line to the catch block and shows me that message. This is how i try to invoke the control: // the delegate: private delegate void TBXTextChanger(string text); private void

Invoke method by MethodInfo

纵然是瞬间 提交于 2019-11-29 07:03:04
I want to invoke methods with a certain attribute. So I'm cycling through all the assemblies and all methods to find the methods with my attribute. Works fine, but how do I invoke a certain method when I only got it's MethodInfo. AppDomain app = AppDomain.CurrentDomain; Assembly[] ass = app.GetAssemblies(); Type[] types; foreach (Assembly a in ass) { types = a.GetTypes(); foreach (Type t in types) { MethodInfo[] methods = t.GetMethods(); foreach (MethodInfo method in methods) { // Invoke a certain method } } } The problem is that I don't know the instance of the class that contains that

MethodInfo.Invoke performance issue

淺唱寂寞╮ 提交于 2019-11-29 05:46:20
I am reading and writing data to and from a file. The data in the file can be floats, doubles, ints etc. The type is not known until runtime. I will refer to data type stored in the file as Tin. Data is read into or written from arrays of type Tout. This type too is not known until runtime. The code sequence is something like this. In the Open method Tin and Tout are known, we can create read and write methods for the known data types. Open(...) { MethodInfo ReadMethod = typeof(...)GetMethod("ReadGeneric").MakeGenericMethod(new Type[] {typeof(Tin), typeof(Tout)})); } The read write loops

Invoke and BeginInvoke

有些话、适合烂在心里 提交于 2019-11-29 02:21:24
问题 Greetings, I am developing some application in C#. At the moment I'm dealing with threading and I have a question that I have in my mind. What is the difference between Invoke and BeginInvoke? I read some thread and I found some useful information here: here However what is the difference between Invoke and BeginInvoke in the following code: private void ProcessRoutine() { for (int nValue = StartFrom; nValue <= EndTo; nValue++) { this.Invoke(this.MyDelegate, nValue); //this.BeginInvoke(this

C# compile error: “Invoke or BeginInvoke cannot be called on a control until the window handle has been created.”

醉酒当歌 提交于 2019-11-29 02:13:58
I just posted a question about how to get a delegate to update a textbox on another form. Just when I thought I had the answer using Invoke...this happens. Here is my code: Main Form Code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Data.OleDb; using System.Collections.Specialized; using System.Text; using System.Threading; delegate void logAdd(string message); namespace LCR_ShepherdStaffupdater_1._0 { public partial class Main : Form { public Main() { InitializeComponent

Dynamically invoke properties by string name using VB.NET

醉酒当歌 提交于 2019-11-29 00:38:06
问题 I'm currently working on a project where a section of the code looks like this: Select Case oReader.Name Case "NameExample1" Me.Elements.NameExample1.Value = oReader.ReadString .... Case "NameExampleN" Me.Elements.NameExampleN.Value = oReader.ReadString .... End Select It continues on for a while. The code is obviously verbose and it feels like it could be improved. Is there any way to dynamically invoke a property in VB.NET such that something like this can be done: Dim sReadString As String