Skip to main content
Home Forums Silverlight Programming Programming with .NET - General DynamicMethod Invoke Instance Method
3 replies. Latest Post by samcov on October 2, 2008.
(0)
Kieren5
Member
26 points
33 Posts
09-19-2008 7:02 PM |
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.aspxCheers
samcov
Participant
966 points
377 Posts
09-19-2008 9:25 PM |
Hi Kieren, take a look at this thread. It may answer some of your questions.
http://silverlight.net/forums/t/14087.aspx
Sam...
10-01-2008 8:57 PM |
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)
10-02-2008 4:21 AM |
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.