Click here to Skip to main content
16,011,611 members
Home / Discussions / C#
   

C#

 
GeneralCalling a function by it's name which has been stored in a string Pin
Gareth_Hastings20-Apr-05 4:37
Gareth_Hastings20-Apr-05 4:37 
GeneralRe: Calling a function by it's name which has been stored in a string Pin
S. Senthil Kumar20-Apr-05 4:52
S. Senthil Kumar20-Apr-05 4:52 
GeneralRe: Calling a function by it's name which has been stored in a string Pin
Gareth_Hastings20-Apr-05 5:06
Gareth_Hastings20-Apr-05 5:06 
GeneralRe: Calling a function by it's name which has been stored in a string Pin
S. Senthil Kumar20-Apr-05 5:54
S. Senthil Kumar20-Apr-05 5:54 
GeneralConstructing Delegate from Object and Method ptr Pin
Tristan Rhodes20-Apr-05 3:55
Tristan Rhodes20-Apr-05 3:55 
GeneralRe: Constructing Delegate from Object and Method ptr Pin
leppie20-Apr-05 4:05
leppie20-Apr-05 4:05 
GeneralRe: Constructing Delegate from Object and Method ptr Pin
Tristan Rhodes20-Apr-05 4:39
Tristan Rhodes20-Apr-05 4:39 
GeneralNever mind - Figured it out Pin
Tristan Rhodes20-Apr-05 4:34
Tristan Rhodes20-Apr-05 4:34 
It seemst that VS.net doesn't like me running away on my own with delegates. So i just reflected it.

If anyone is interested - Here is the code (Exception Handling omitted for ease of reading):

<br />
		/// <summary><br />
		/// Invoke a delegate via reflection<br />
		/// </summary><br />
		/// <param name="delegateType">Type of the delegate to construct</param><br />
		/// <param name="obj">The object to construct the delegate from. (Can be null<br />
		/// for static methods)</param><br />
		/// <param name="method">The method on the object to use as a delegate</param><br />
		/// <returns>The constructed delegate, or null if there was an error in<br />
		/// instantiation.</returns><br />
		public static object InvokeDelegateViaReflection(Type delegateType, object obj, MethodInfo method)<br />
		{<br />
			//Locate constructor method<br />
			ConstructorInfo ci = delegateType.GetConstructors()[0];<br />
<br />
			//Construct arguments<br />
			object[] args = new object[]{@obj, method.MethodHandle.GetFunctionPointer()};<br />
<br />
			//Call constructor<br />
			object result = ci.Invoke(<br />
				BindingFlags.Public | BindingFlags.Static | BindingFlags.CreateInstance,<br />
				null,args,null);	<br />
<br />
			//return new delegate<br />
			return result;<br />
		}<br />


Hope that helps someone

Cata
GeneralRe: Never mind - Figured it out Pin
leppie20-Apr-05 8:51
leppie20-Apr-05 8:51 
GeneralIDREES Pin
idreesbadshah20-Apr-05 3:41
idreesbadshah20-Apr-05 3:41 
GeneralRe: IDREES Pin
Colin Angus Mackay20-Apr-05 3:52
Colin Angus Mackay20-Apr-05 3:52 
GeneralRe: IDREES Pin
DavidNohejl20-Apr-05 4:41
DavidNohejl20-Apr-05 4:41 
GeneralRe: IDREES Pin
Colin Angus Mackay20-Apr-05 4:45
Colin Angus Mackay20-Apr-05 4:45 
GeneralRe: IDREES Pin
Anonymous21-Apr-05 4:09
Anonymous21-Apr-05 4:09 
GeneralRe: IDREES Pin
Colin Angus Mackay21-Apr-05 4:20
Colin Angus Mackay21-Apr-05 4:20 
GeneralProblem with .NET 2 Beta 2 (C# Express Beta 2) Pin
Jucs20-Apr-05 3:31
Jucs20-Apr-05 3:31 
GeneralRe: Problem with .NET 2 Beta 2 (C# Express Beta 2) Pin
Robert M. Bouwens20-Apr-05 5:14
Robert M. Bouwens20-Apr-05 5:14 
GeneralProblem with StreamReader.BaseStream.Position Pin
AfzalHassen20-Apr-05 3:27
AfzalHassen20-Apr-05 3:27 
QuestionHow to add flash into C# applications? Pin
Alper Camel20-Apr-05 3:20
Alper Camel20-Apr-05 3:20 
GeneralAutocomplete/intellisence in a multiline edit box Pin
djkno320-Apr-05 2:28
djkno320-Apr-05 2:28 
GeneralRe: Autocomplete/intellisence in a multiline edit box Pin
Ashok Dhamija20-Apr-05 17:41
Ashok Dhamija20-Apr-05 17:41 
GeneralRe: Autocomplete/intellisence in a multiline edit box Pin
djkno321-Apr-05 10:08
djkno321-Apr-05 10:08 
GeneralWindows Forms - Programmatically scroll a listview control to the selected item Pin
abcxyz8220-Apr-05 2:15
abcxyz8220-Apr-05 2:15 
GeneralRe: Windows Forms - Programmatically scroll a listview control to the selected item Pin
Dave Kreskowiak20-Apr-05 5:56
mveDave Kreskowiak20-Apr-05 5:56 
QuestionHow to extract the sql query from a report Pin
Ana-Gabriela Clem20-Apr-05 1:52
Ana-Gabriela Clem20-Apr-05 1:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.