C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Dynamic Method Invocation using Reflection - With Parameters and Return Value


Posted Date: 25 Jun 2008    Resource Type: Code Snippets    Category: Reflection
Author: Brainstorming GuyMember Level: Diamond    
Rating: Points: 20



Hi,
In this code snippet, you will be knowing how to create an object and invoke the method dynamically.
Class which we are going to instantiate and invoke a method in that dynamically.

public class ReflectionClass
{
public int AddNumbers(int number1, int number2)
{
return number1 + number2;
}
}

To invoke the method, put the following piece of code. Make you have imported or written using for System.Reflection.

Type ReflectionObject = typeof(ReflectionClass);
object classObject = Activator.CreateInstance(ReflectionObject);
ReflectionObject.GetMethod("AddNumbers").Invoke(classObject, new object[] {3,4 });
Console.WriteLine(returnValue.ToString());




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Dynamic Method Invocation using Reflection - Without Parameters
Previous Resource: Dynamica invocation of a Method in DLL using C#
Return to Discussion Resource Index
Post New Resource
Category: Reflection


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use