Page view counter
DynamicMethod Invoke Instance Method
Last post 10-02-2008 4:21 AM by samcov. 3 replies.
Sort Posts:
09-19-2008 7:02 PM
DynamicMethod Invoke Instance Method

Is it possible to invoke an instance method from a DynamicMethod in Silverlight?

This sample shows how to access an instance field on a class:
http://msdn.microsoft.com/en-us/library/z43fsh67(VS.95).aspx

Is it possible to call a method on a class using a similar technique, any guidance or samples.

There is a sample for .Net 3.5, but it doesn't work in Silverlight because you can only use the first DynamicMethod constructor (the rest have a secuirty attribute :S ):
http://msdn.microsoft.com/en-us/library/ms228976.aspx

Cheers

Kieren5

Loading...
Joined on 07-22-2008
Brisbane, Qld, Australia
Posts 32
09-19-2008 9:25 PM
Re: DynamicMethod Invoke Instance Method

Hi Kieren, take a look at this thread.  It may answer some of your questions.

http://silverlight.net/forums/t/14087.aspx

Sam...

"The difference between genius and stupidity is that genius has its limits." - Albert Einstein

samcov

Loading...
Joined on 03-26-2008
Posts 274
10-01-2008 8:57 PM
Marked as Answer
Re: Re: DynamicMethod Invoke Instance Method

Using reflection emit and the technique described in this post (with sample code):

http://www.xtremedotnettalk.com/showthread.php?t=96952

I was able to invoke an instance method on a class.

The only change necessary is the constructor of the DynamicMethod. The sample code uses this constructor, which is not allowed in Silverlight (for security):
[SecurityCriticalAttribute]
public DynamicMethod(
string name,
Type returnType,
Type[] parameterTypes,
Type owner
)

Change it to this one:
public DynamicMethod(
string name,
Type returnType,
Type[] parameterTypes
)
Kieren5

Loading...
Joined on 07-22-2008
Brisbane, Qld, Australia
Posts 32
10-02-2008 4:21 AM
Re: Re: DynamicMethod Invoke Instance Method

Kieren5:

Using reflection emit and the technique described in this post (with sample code):

http://www.xtremedotnettalk.com/showthread.php?t=96952

I was able to invoke an instance method on a class.

The only change necessary is the constructor of the DynamicMethod. The sample code uses this constructor, which is not allowed in Silverlight (for security):
[SecurityCriticalAttribute]
public DynamicMethod(
string name,
Type returnType,
Type[] parameterTypes,
Type owner
)

Change it to this one:
public DynamicMethod(
string name,
Type returnType,
Type[] parameterTypes
)

That information and the reasons for it are ALL in the link I gave you, but I'm glad you're satisfied.

"The difference between genius and stupidity is that genius has its limits." - Albert Einstein

samcov

Loading...
Joined on 03-26-2008
Posts 274
Microsoft Communities