I want to generate a list of all methods in a class or in a directory of classes. I also need their return types. Outputting it to a textfile will do...Does anyone know of a tool, lug-in for VS or something which will do the task? Im using C# codes by the way and Visual Studio 2008 as IDE
b) A class should contain an average of less than 30 methods, resulting in up to 900 lines of code.
To list the methods for this class, one approach is to use the dir() function in Python. The dir() function will return all functions and properties of the class.
In Visual Studio 2015, View > Other Windows > Resource View. The keyboard shortcut is Ctrl + Shift + E .
In Python, this can be achieved by using __repr__ or __str__ methods. __repr__ is used if we need a detailed information for debugging while __str__ is used to print a string version for the users. Important Points about Printing: Python uses __repr__ method if there is no __str__ method.
Sure - use Type.GetMethods(). You'll want to specify different binding flags to get non-public methods etc. This is a pretty crude but workable starting point:
using System;
using System.Linq;
class Test
{
static void Main()
{
ShowMethods(typeof(DateTime));
}
static void ShowMethods(Type type)
{
foreach (var method in type.GetMethods())
{
var parameters = method.GetParameters();
var parameterDescriptions = string.Join
(", ", method.GetParameters()
.Select(x => x.ParameterType + " " + x.Name)
.ToArray());
Console.WriteLine("{0} {1} ({2})",
method.ReturnType,
method.Name,
parameterDescriptions);
}
}
}
Output:
System.DateTime Add (System.TimeSpan value)
System.DateTime AddDays (System.Double value)
System.DateTime AddHours (System.Double value)
System.DateTime AddMilliseconds (System.Double value)
System.DateTime AddMinutes (System.Double value)
System.DateTime AddMonths (System.Int32 months)
System.DateTime AddSeconds (System.Double value)
System.DateTime AddTicks (System.Int64 value)
System.DateTime AddYears (System.Int32 value)
System.Int32 Compare (System.DateTime t1, System.DateTime t2)
System.Int32 CompareTo (System.Object value)
System.Int32 CompareTo (System.DateTime value)
System.Int32 DaysInMonth (System.Int32 year, System.Int32 month)
(etc)
You can get at these lists very easily with reflection. e.g. with Type.GetMethods()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With