473,699 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3044

<ay****@gmail.c om> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.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 MakeGenericMeth od 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.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.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 GetGenericArgum ents 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
301
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 interface methods are actually only in the parent type -- inherited. This works in C#... but when I try to do it using Reflection.Emit it claims no knowledge of the inherited methods, and expects me to define the methods again in the class I'm...
2
3636
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
1210
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 assembly, for example a generic method parameter declared as: System.Collections.Generic.List<int> the full name of that parameter type returned by reflection is :
9
4165
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 System.Reflection. Regards, Michael
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.