如何查看 class 作为参数传递到 Rider 模板中的内容?
How to see what class was passed into template in Rider as an argument?
我经常在 Rider 中调试 C# 模板,想知道它是否可行,如果可以,那么如何查看 class 进入 Rider 模板的内容?
示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
}
public void DoSomething<T>() {
//What is a type of T?
}
}
}
使用全新安装和默认设置,您可以在 "Variables" window 中看到调试时可以看到的变量类型:
我认为之前标记的答案是正确的,但仅限于特定的案例场景。
如果我对问题的理解正确,它可以改写为“如何使用 Rider 调试器检查通用参数的类型?”如果是这样的话,@nvoigt 的答案是正确的,因为调试器会向您显示断点范围内每个变量的类型。因此在所示示例中:
public void DoSomething<T>(T arg)
{
...
}
argument
的类型在变量 window 中很容易读取:
然而,如果 generic argument 'T'
不是 method argument 'arg'
的类型,如:
public T DoSomething<T>(string arg)
{
...
}
那么 arg
将是定义的 string
类型。在这种情况下,您需要查看 Frames window - 左边的 ot Variables。在那里,在第一行您将能够看到执行暂停的方法(通过断点),如果您展开 window 您将看到类似的内容:
Program.DoSomething<TypePassedAsGenericArgument>()
其中 TypePassedAsGenericArgument
将是类型的全名,a.k.a - 命名空间 + class 名称:
我认为这个说明可能会帮助一些新的编码人员。去解决那些 BUG!
我经常在 Rider 中调试 C# 模板,想知道它是否可行,如果可以,那么如何查看 class 进入 Rider 模板的内容?
示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
}
public void DoSomething<T>() {
//What is a type of T?
}
}
}
使用全新安装和默认设置,您可以在 "Variables" window 中看到调试时可以看到的变量类型:
我认为之前标记的答案是正确的,但仅限于特定的案例场景。
如果我对问题的理解正确,它可以改写为“如何使用 Rider 调试器检查通用参数的类型?”如果是这样的话,@nvoigt 的答案是正确的,因为调试器会向您显示断点范围内每个变量的类型。因此在所示示例中:
public void DoSomething<T>(T arg)
{
...
}
argument
的类型在变量 window 中很容易读取:
然而,如果 generic argument 'T'
不是 method argument 'arg'
的类型,如:
public T DoSomething<T>(string arg)
{
...
}
那么 arg
将是定义的 string
类型。在这种情况下,您需要查看 Frames window - 左边的 ot Variables。在那里,在第一行您将能够看到执行暂停的方法(通过断点),如果您展开 window 您将看到类似的内容:
Program.DoSomething<TypePassedAsGenericArgument>()
其中 TypePassedAsGenericArgument
将是类型的全名,a.k.a - 命名空间 + class 名称:
我认为这个说明可能会帮助一些新的编码人员。去解决那些 BUG!