.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Going from MethodInfo of G.M to MethodInfo of G.M?

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :.NET Framework

Edit: I'm doing Reflection.Emit(opcode, MethodInfo)

There is a generic type G<T>, it is instantiated as e.g. G<int32> with a method M. (I don't know what type G will be in advance).

I'm given that MethodInfo of G<int32>.M. I want to get the original corresponding MethodInfo on the generic type definition which would have the different DeclaringType, G<T>.

Is there any simple and efficient way to do this?

The only way I can think of doing this is
Do G<int32>.GetGenericTypeDefinition() to get G<T>
Do GetMethods() on G<T>
Iterate through all the results and compare them to the original method in question.

It seems complex and like it would be really inefficient. From what I understand the two MethodInfos should have the same metadata token. Is there some better way?


View Complete Post

More Related Resource Links

How to pass double pointers for COM Interop via MethodInfo.Invoke ?

Hello, I need to make COM IntetrOp at runtime using reflections. My native COM Object's exposed methods have some parameters as pointers (DWORD*) and some double pointers (DWORD**) and some are user defined types(e.g SomeUDTType objSmeUDTType) and its pointer to pointer(i.e. SomeUDTType **pSomeUDTType). I need to pass pointers to pointers. For now how can I be able to populate "object" array as pointers to pointers of SomeUDTType. Working Example:      STDMETHODIMP MyCallableMethod(DWORD *value_1,BSTR *bstrName,WESContext **a_wesContext tlbImp.exe generated output:      DTINIDLLib.RuntimeCallingClass.MyCallableMethod(ref uint, ref string, System.IntrPtr) Regards UsmanMutlithreading

Retrieving out parameter/arguments from MethodInfo.Invoke

Hi everybody.For example, I have a method like this:public int DoSomething(int x, out int z){   z = x + 1;   return x + 2;}Then I invoke this method using MethodInfo.Invoke via reflection:MethodInfo myMethod = this.GetType().GetMethod("DoSomething");int result = myMethod.Invoke(this, new object[] { 5, 0 });The code working fine, I got the result = 7 (which is from x + 2).But how I can get the z ? (which is x + 1) ?Please advise,Thanks,Lok_Tan

Use ActionInvoker to Return MethodInfo from a Url


I'm trying to create my own smart ActionLink htmlhelper that determines if a user is authorized to perform the action that the link points to. If they are not authorized then I want to launch a javascript modal login box to screen.

I have gotten it to work in cases where my method names are all unique. But I need it to be more intelligent and know exactly which of the overloaded Methods will be invoke based on the url and therefore not run into an ambiguous exception. Therefore I need to use the ActionInvoker but I'm not sure how. 


Here is what I am trying to do:


string actionLinkUrl = UrlHelper.GenerateUrl(routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, routeCollection, requestContext, includeImplicitMvcValues);

            // Use ActionInvoker to return a MethodInfo myMethod based on actionLinkUrl.  
            //This is the part I need help on
            // TODO: Initialize this from ActionInvoker using the actionLinkUrl
            MethodInfo myMethod; 

            // Next I am finding out if AuthorizeAttribute is decorated on the Method.
            // I can do this already. Though maybe there is a better way.
            bool hasAttribute = myMethod.GetCustomAttributes(typeof(AuthorizeAttribute), true).Length > 0; 



MethodInfo.Invoke performance



I'm using heavily reflection in our business code since we relay on database structures to manage workflows and validations. Methods that I'm invoking usually have known parameters and known return types. Invoke method is slow so I'm wondering does .NET 3.5 offers anything else that is faster. Most called methods are instance methods.

To further clarify my question: I read from my database an ordered sequence of methods that needs to be called. This methods have the same signature and they have to be called in order. This operation is executed many times when the user is active. Since we deploy our solution onto a terminal server every bit of a performance gain is at least 20-50 times multiplied.


Failed To Convert Parameter Value From A String To A Int32

 This is my stored procedure: PROCEDURE[dbo].[uspEXPENDITURE_DETAILS] ( @ExpDetailsID int=0 output, @ExpDet_ExpID int, @ExpDet_Municipality_ID nvarchar(50), @ExpDetGeneralFund money, @ExpDetSpecialRevenue money, @ExpDetCapitalProjects money, @ExpDetTotal money, @Exp_Reporting_Year varchar(10), @ExpComments varchar(max), @Contact_ID int ) AS BEGIN  -- SET NOCOUNT ON added to prevent extra result sets from  -- interfering with SELECT statements.  SET NOCOUNT ON; deletefrom [dbo].[TBL_EXPENDITURE_DETAILS] where ExpDet_ExpID=@ExpDet_ExpID and ExpDet_Municipality_ID=@ExpDet_Municipality_ID and Exp_Reporting_Year=@Exp_Reporting_Year If@ExpDetailsID >= 0 Begin INSERT     INTO [dbo].[TBL_EXPENDITURE_DETAILS] ([ExpDet_ExpID] ,[ExpDet_Municipality_ID] ,[ExpDetGeneralFund] ,[ExpDetSpecialRevenue] ,[ExpDetCapitalProjects] ,[ExpDetTotal] ,[Exp_Reporting_Year] ,[ExpComments] ,[ExpDetCreatedBy] ,[ExpDetCreateDate]) VALUES  (@ExpDet_ExpID , @ExpDet_Municipality_ID , @ExpDetGeneralFund, @ExpDetSpecialRevenue , @ExpDetCapitalProjects, @ExpDetTotal, @Exp_Reporting_Year, @ExpComments, @Contact_ID, GetDate () )    SET @ExpDetailsID = SCOPE_IDENTITY()  return @ExpDetailsID end   Public Sub CreateExpenseDetails() Dim item As GridViewRow Dim txtExpGenFund, txtExpD

BitArray -> Int32

I need to take my BitArray and convert it to a Int32.  I havent found any ways to do this using the BitArray class.  Am i missing something?...Simply casting it didnt work either. Heres my code (Its for converting Big-Endian values,  It reads 4 bytes ahead and the file and determines the value,  Open to suggestions on that code too but this problem came up first so i cant even test it) public BitArray NullBits(BitArray bits, int index)<br/> {<br/> for (int i = index; i < bits.Length; i++)<br/> {<br/> bits[i] = false;<br/> }<br/> return bits;<br/> }<br/> public BitArray RemoveEndianBits(BitArray bits)<br/> {<br/> //How many Values to shift over<br/> int shift = 1;<br/> //For each bit<br/> for (int i = 0; i < bits.Length; i++)<br/> {<br/> if ((i+1 % 8) == 0)<br/> {<br/> shift+= 1;<br/> }<br/> if (i + shift < bits.Length)<br/> {<br/> bits[i] = bits[i + shift];<br/> }<br/> else<br/> {<br/> bits[i] = false;<br/> }<br/> }<br/> return bits;<br/> }<br/> public int ReadValue(FileS

failed to convert parameter value from a string to a int32

I am not sure where my app is failing but most probably this is where it is failing.. I think lblExpID.Text is the culprit. Here's the relvant part of my code: Dim lblExpID As Label For Each item In LSGrid.Rows lblExpID = item.FindControl("lblID") If txtExpGenFund.Text <> "" Then sqlArray(i) = ExpDetailsID & "," & (lblExpID.Text) & "," & MunID & "," & _ Val(txtExpGenFund.Text) & "," & Val(txtExpDetSpecialRevenue.Text) & "," & _ Val(txtExpDetCapitalProjects.Text) & "," & expTotal & "," & reportingYear & "," & "Test Comments" & "," & UserID End If Can u help me identify why i am getting this error looking at the sp below: PROCEDURE [dbo].[uspEXPENDITURE_DETAILS] ( @ExpDetailsID int=0 output, @ExpDet_ExpID int, @ExpDet_Municipality_ID nvarchar(50), @ExpDetGeneralFund money, @ExpDetSpecialRevenue money, @ExpDetCapitalProjects money, @ExpDetTotal money, @Exp_Reporting_Year varchar(10), @ExpComments varchar(max), @Contact_ID int ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; delete from [dbo].[TBL_EXPENDITURE_DETAILS] where ExpDet_ExpID=@ExpDet_ExpID and ExpDet_Municipality_ID=@ExpDet_Municipality_ID and Ex

dealing with nulls in a Int32.Parse(string) statement

How do I deal with null values in this section it throws errors when they leave the field blank it is a small order form and they don't have too add data to all the fields .   comm.Parameters.Add("@item_9223", System.Data.SqlDbType.Int);                comm.Parameters["@item_9223"].Value = Int32.Parse(txtitem_9223.Text);                comm.Parameters.Add("@item_9129", System.Data.SqlDbType.Int);                comm.Parameters["@item_9129"].Value = Int32.Parse(txtitem_9129.Text);                comm.Parameters.Add("@item_42795", System.Data.SqlDbType.Int);                comm.Parameters["@item_42795"].Value = Int32.Parse(txtitem_42795.Text);                comm.Parameters.Add("@item_30695", System.Data.SqlDbType.Int);                comm.Parameters["@item_30695"].Value = Int3

Showing positive/negative sign in the output of Int32.ToString(string)

Hi,   Now this may be really simple but I'm unable to make it work or find it in MSDN. What is the format specifier for showing +/- sign of an Int32? I have tried "+0", "-0" and "+-0" and all of them give wrong results for either positive or negative or both kind of values. Note: The specifier should return "+0" for 0.

Analysis Services Using Oracle as a Data Source Data Types mismatch System.Int32 and System.Int64

Hi everyone, I searched for this issue but there is only 4 questions about it in this forum from 2007 I hope that someone can help me. Im usign SASS 2008 using a Oracle as a datasource.  I already have my fact tables linked with dimensions, lets say, FACTID System.Int64 with DIMENSIONID System.Int64 (My dimensions are replaced by named querys and work perfectly) I add a new table to my DSV and the NEWDIMENSIONID looks like System.Int64, but at the moment I replace the table with a named query (I have to use Oracle quering) the NEWDIMENSIONID changes to System.Int32 .  After that I cant relate the fact table with the dimension table. Actions: Looked for the columns that relate from Oracle... both are NUMBER(5). Looked for the differences between my other tables that are already related as System.Int64 and there is not a single difference between the ones that works and the one who doesnt. Solutions Ive tried and didnt work: 1. Cast the column as SQL query didnt work it send an error.  Looks kind of obvious because we are quering Oracle... but I had to try.  CAST( X AS BIGINT) 2. Cast the column as Oracle query . TO_NUMBER 3. Do it inside the server using the Analysis Services Enterprise insted of my Analysis Services Developer. Same issue.   Any ideas? suggestions?   Please? Thank you very much ;) Sincerly Adriana L. PS. At the begging of

Re:Type 'Int32' is not a valid entity type.



I have been trying to pull a database table with a small int field into my dbml file, the entity type rendered itself as a short initially, and I got the following error message:

Type 'Int16' is not a valid entity type.  Entity types cannot be a primitive type or a simple type like string or Guid.


Then i converted the memeber type to a int instead of the short and i ran into the following error:

 Type 'Int32' is not a valid entity type.  Entity types cannot be a primitive type or a simple type like string or Guid.  


I am just not able to get around the issue, can anyone please give in some constructive feedback as to why is that possibly happening?

The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value t


Hi All,

        int maxAge = db.tbl_zaposlenis.Where(p => p.IdSifra == 22)
                         .Max(p => p.IdSifra);

        zaposleni.IdSifra = maxAge;

How to display the largest number in the "IdSifra?


Converting byte[] array to Int32


Hi guys,

I am trying to read in a binary file created by a legacy VBA application.

One of the sections of the file is a date, which was written out as a four byte segment equivalent a VBA long with value 40451.

In the binary array this is represented as: 33, 67, 101, 135

If I convert the binary array back into a long in VBA I get the number 40451 again.

However, if I create a four byte array in C# and try and convert that to an Int32 using BitConverter I get the value -2023406815.

I have tried reversing the byte order but not getting anything close to 40451.

Anyone got any ideas on how to get the same value as the original VBA long?



how to convert session to int32?


Currently i using gridview to display a person informaton based on his login id however it show error because the session is set to ToString. Is it a way to convert the session to int32?

protected void Button1_Click(object sender, EventArgs e)

        string Person_ID = this.Session["User_ID"].ToString();

        SqlDataSource sds = new SqlDataSource();
        sds.ConnectionString = ConfigurationManager.ConnectionStrings["PersonDB"].ToString();

        sds.SelectCommand = " SELECT * FROM [Person] WHERE [User_ID] =Person_ID";

        DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);

        GridView1.DataSource = dv;


CInt and Int32 conversion problem


in the codebehind I gave a line gives always zero eventhough textbox1 is not null or zero. I type a number but it return zero...when I try Int32.Parse also it does not work and gives "Input string was not in a correct format." error.please help...




Object of type 'System.Int32' cannot be converted to type 'System.String


When i'm trying to update a table using dynamic data, i'm getting the following error. I was trying to google the solution for the whole day, but it didnt work. I tried to declare the type of parameters like this

<asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true"
                onupdating="DetailsDataSource_Updating" > <UpdateParameters><asp:Parameter Name="PK_ID" Type="Int32" /><asp:Parameter Name="id" Type="Int32" />
                <asp:Parameter Name="c_titulu" Type="Int32" />
                <asp:Parameter Name="perio" Type="Int32" />

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend