Stopbyte

How can i retrieve all references of my Methods and class members from Code in C#?

Lets say i have a C# Class defined this way:

public class SampleClass
{
    public string SampleMember {get;set;}
    
    public void SampleMethod(string param1)
    {
        // Does something here.
    }
}

The SampleClass above has two members, SampleMember (property) and SampleMethod. Now is there any way i can Retrieve list of methods,and classes that are Referencing my Method and my Sample Member in C# using Reflection?

thanks

You want get all methods in your class?

using System;
using System.Reflection;
using System.Reflection.Emit;


Type myType =(typeof(SampleClass));
// Get the public methods.
MethodInfo[] myArrayMethodInfo = myType.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);
Console.WriteLine("\nThe number of public methods is {0}.", myArrayMethodInfo.Length);

Read more you can on site Microsoft Link

1 Like

I guess your answer is not perfect @ivan.norin Since @afree asked for this:

is there any way i can Retrieve list of methods,and classes that are Referencing my Method and my Sample Member in C# using Reflection?

But instead you gave him the way to retrieve the list of methods in a class!

But instead you gave him the way to retrieve the list of methods in a class!

I probably did not right understand what he wants :slight_smile: