Click here to Skip to main content
15,915,164 members
Home / Discussions / C#
   

C#

 
GeneralRe: selected event of CheckedListBox--plz help Pin
Wayne Phipps10-Mar-07 1:03
Wayne Phipps10-Mar-07 1:03 
Questionselected event of CheckedListBox--plz help Pin
pashitech9-Mar-07 19:08
pashitech9-Mar-07 19:08 
Questionhow to draw listbox items with different itemheight when i selected a item Pin
goldli9-Mar-07 18:26
goldli9-Mar-07 18:26 
AnswerRe: how to draw listbox items with different itemheight when i selected a item Pin
Mike Hankey10-Mar-07 2:48
mveMike Hankey10-Mar-07 2:48 
QuestionMail Pin
Jijo BP9-Mar-07 17:46
Jijo BP9-Mar-07 17:46 
AnswerRe: Mail Pin
S. Senthil Kumar10-Mar-07 5:10
S. Senthil Kumar10-Mar-07 5:10 
QuestionWord Template Programming in C# Pin
satsumatable9-Mar-07 17:36
satsumatable9-Mar-07 17:36 
QuestionMethod Matching Pin
SHaroz9-Mar-07 17:20
SHaroz9-Mar-07 17:20 
Hello everyone,

I am trying to find all methods that have a particular signature. In other words, I want all methods that match the return type and parameter types of a specified method. I have a solution, but I was wondering if a more elegant approach exists. Using delegates is one possibility, but delegates are not very “edit-and-continue” friendly.

Here is my current solution:
void findSimilarMethods()
{
    MethodInfo example = this.GetType().GetMethod("ExampleMethod");
    ParameterInfo[] parameters = example.GetParameters();
    List<MethodInfo> matches = new List<MethodInfo>();

    MethodInfo[] methods = this.GetType().GetMethods();
    foreach (MethodInfo current in methods) {
        ParameterInfo[] currentParams = current.GetParameters();
        if ( current.ReturnType != example.ReturnType )
            continue;
        if ( currentParams.Length != parameters.Length )
            continue;
        if ( !ParameterEquality(parameters, currentParams) )
            continue;
        matches.Add(current);
    }
}

// a helper method to check parameter type equality
bool ParameterEquality(ParameterInfo[] a, ParameterInfo[] b)
{
    if (a.Length != b.Length)
        return false;
    for (int i = 0; i < a.Length; i++)
        if (a[i].GetType() != b[i].GetType())
            return false;
    return true;
}


Any suggestions would be greatly appreciated.

-Steve
AnswerRe: Method Matching Pin
S. Senthil Kumar10-Mar-07 5:13
S. Senthil Kumar10-Mar-07 5:13 
QuestionConstructors in C# Pin
Captain See Sharp9-Mar-07 15:57
Captain See Sharp9-Mar-07 15:57 
AnswerRe: Constructors in C# Pin
Scott Dorman9-Mar-07 17:31
professionalScott Dorman9-Mar-07 17:31 
AnswerRe: Constructors in C# Pin
Zoltan Balazs10-Mar-07 1:59
Zoltan Balazs10-Mar-07 1:59 
GeneralRe: Constructors in C# Pin
Captain See Sharp10-Mar-07 13:42
Captain See Sharp10-Mar-07 13:42 
AnswerRe: Constructors in C# Pin
S. Senthil Kumar10-Mar-07 5:20
S. Senthil Kumar10-Mar-07 5:20 
GeneralRe: Constructors in C# Pin
Captain See Sharp10-Mar-07 13:37
Captain See Sharp10-Mar-07 13:37 
GeneralRe: Constructors in C# Pin
S. Senthil Kumar10-Mar-07 13:46
S. Senthil Kumar10-Mar-07 13:46 
GeneralRe: Constructors in C# Pin
Captain See Sharp10-Mar-07 13:51
Captain See Sharp10-Mar-07 13:51 
GeneralRe: Constructors in C# Pin
gumi_r@msn.com10-Mar-07 14:29
gumi_r@msn.com10-Mar-07 14:29 
GeneralRe: Constructors in C# Pin
Captain See Sharp10-Mar-07 13:54
Captain See Sharp10-Mar-07 13:54 
GeneralRe: Constructors in C# Pin
S. Senthil Kumar10-Mar-07 14:21
S. Senthil Kumar10-Mar-07 14:21 
QuestionState Mangement Pin
Renuka Reddy9-Mar-07 15:33
Renuka Reddy9-Mar-07 15:33 
AnswerRe: State Mangement Pin
Udhaya Kumar.D10-Mar-07 4:19
Udhaya Kumar.D10-Mar-07 4:19 
Questionadding a property to user control Pin
dino20949-Mar-07 12:57
dino20949-Mar-07 12:57 
AnswerRe: adding a property to user control Pin
Captain See Sharp9-Mar-07 16:06
Captain See Sharp9-Mar-07 16:06 
QuestionIRIS Recgonition Pin
shdelpiero9-Mar-07 11:29
shdelpiero9-Mar-07 11:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.