[API Proposal]: DiagnosticMethodInfo should return full method signature
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Background and motivation
With .NET 10, `DiagnosticMethodInfo` does not allow you to obtain method parameters, which can be problematic when identifying the actual method called in the stack when its parameters are overloaded.
The parameter types would be sufficient if the parameter names cannot be reliably retrieved in an AOT context.
```csharp
try
{
throw new InvalidOperationException("oops");
}
catch (Exception ex)
{
StackFrame[] frames = new StackTrace(ex, true).GetFrames();
for (int i = 0; i < frames.Length; i++)
{
StackFrame frame = frames[i];
DiagnosticMethodInfo? methodInfo = DiagnosticMethodInfo.Create(frame);
string methodName = $"{methodInfo?.DeclaringTypeName}.{methodInfo?.Name}";
// there is no way to get full method signaure with parameters from DiagnosticMethodInfo
Console.WriteLine($"Method: {methodName}");
}
}
```
Returns `AssamblyName.ClassName.MethodName`
### API Proposal
```csharp
namespace System.Diagnostics
{
public sealed class DiagnosticMethodInfo
{
public string Name { get; }
public string NameWithParams { get; } // new API
public string DeclaringTypeName { get; }
public string DeclaringAssemblyName { get; }
public static DiagnosticMethodInfo? Create(Delegate @delegate);
public static DiagnosticMethodInfo? Create(StackFrame frame);
}
}
```
### API Usage
```csharp
try
{
throw new InvalidOperationException("oops");
}
catch (Exception ex)
{
StackFrame[] frames = new StackTrace(ex, true).GetFrames();
for (int i = 0; i < frames.Length; i++)
{
StackFrame frame = frames[i];
DiagnosticMethodInfo? methodInfo = DiagnosticMethodInfo.Create(frame);
string methodName = $"{methodInfo?.DeclaringTypeName}.{methodInfo?.NameWithParams}";
Console.WriteLine($"Method: {methodName}");
}
}
```
Should return `AssamblyName.ClassName.MethodName(String)`
### Alternative Designs
_No response_
### Risks
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.