简体   繁体   English

如何查看哪个类作为参数传递给 Rider 中的模板?

[英]How to see what class was passed into template in Rider as an argument?

I am debugging C# templates in Rider a lot and would like to know whether or not it is possible and if yes, then how to see what class is coming into template in Rider?我在 Rider 中调试了很多 C# 模板,想知道它是否可行,如果是,那么如何在 Rider 中查看哪些类进入模板?

Example:示例:

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?
        }
    }
}

With a fresh install and the default settings, you can see the variable type in the "Variables" window that you can see when you debug:使用全新安装和默认设置,您可以在调试时可以看到的“变量”窗口中看到变量类型:

在此处输入图片说明

I think the previously marked answer is correct, but only for a specific case scenario.我认为先前标记的答案是正确的,但仅适用于特定情况。

If I understand the question correctly, it can be rephrased to "How to inspect the type of a generic parameter using Rider debugger?"如果我正确理解了该问题,则可以将其改写为“如何使用 Rider 调试器检查通用参数的类型?” If so @nvoigt's answer is correct in the sense that the debugger shows you the type of each variable in the scope of the breakpoint.如果是这样,@nvoigt 的答案是正确的,因为调试器会向您显示断点范围内每个变量的类型。 Thus in the shown example:因此,在显示的示例中:

public void DoSomething<T>(T arg)
{
    ...
}

The type of argument is easily readable in the Variables window: argument类型在“变量”窗口中很容易阅读: 在此处输入图片说明

However if the generic argument 'T' is not the type of the method argument 'arg' as in:但是,如果generic argument 'T'不是method argument 'arg'的类型,如下所示:

public T DoSomething<T>(string arg)
{
    ...
}

Then arg will be of type string as was defined.然后arg将是定义的string类型。 In that case you need to look at the Frames window - to the left ot Variables.在这种情况下,您需要查看框架窗口 - 左侧的变量。 There, on the first line you will be able to see the method where the execution is halted (by the breakpoint) and if you expand that window you will see something like:在那里,在第一行,您将能够看到执行停止的方法(通过断点),如果您展开该窗口,您将看到如下内容:

Program.DoSomething<TypePassedAsGenericArgument>()

where TypePassedAsGenericArgument will be the full name of the type, aka - namespace + class name:其中TypePassedAsGenericArgument将是类型的全名,又名 - 命名空间 + 类名:

在此处输入图片说明

I think this clarification might help some new coders out there.我认为这个澄清可能会帮助一些新的编码人员。 Go get those BUGS!去拿那些BUG!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM