473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Reflection.Emit and generic methods

How do I use Reflection.Emit to produce code similar to this?

public void bar<T>()
{
}
public void foo<J>()
{
bar<J>();
}

More specifically, I don't know how to bind the method call using
Reflection.Emit.
Any suggestions?

The IL that is generated is:

..method public hidebysig instance void foo<J>() cil managed
{
// Code Size: 9 byte(s)
.maxstack 8
L_0000: nop
L_0001: ldarg.0
L_0002: call instance void dempo::bar<!!0>()
L_0007: nop
L_0008: ret
}

But I don't see a way to get the !!0 from Reflection.Emit.

Nov 18 '05 #1
3 3022

<ay****@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
How do I use Reflection.Emit to produce code similar to this?

public void bar<T>()
{
}
public void foo<J>()
{
bar<J>();
}

More specifically, I don't know how to bind the method call using
Reflection.Emit.
Any suggestions?


Look at the MakeGenericMethod method on MethodInfo. It should allow you to
bind to the method you want to call with the type parameters you want.
Nov 19 '05 #2
I looked at them, but that isn't the problem, I have the method info
for bar, I just don't know what to pass to make generic method?
From foo(), how do I get what J is?


Nov 19 '05 #3

<ay****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I looked at them, but that isn't the problem, I have the method info
for bar, I just don't know what to pass to make generic method?
From foo(), how do I get what J is?


Ahh, I see what you mean now. Try using the GetGenericArguments method, that
should return an array of types which will represent the generic arguments
for hte method.
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Wood | last post by:
I'm creating a new type (using Reflection.Emit), and using SetParent to have it derive from an existing type. I'm using AddInterfaceImplementation to have the type support an interface, but the...
2
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
0
by: Konrad Kaczanowski | last post by:
Hi all, I'm creating code generator for wrappers of some c# classes. With the introduction of c# 2.0 and generics the following problem arises. When encountering generic types anywhere inside the...
9
by: Michael Sander | last post by:
Hello ng, anyone knowns how to add a reference to an assembly to System.Reflection.AssemblyBuilder? In System.Web.Compilation.AssemblyBuilder is a function like AddAssemblyReference, but not in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.