1

I'm new to C# in ASP.Net. I'm using VS 2015 and a NetCore project. I'm used in PHP (PHPStorm IDE) to Control-Click a method name to go to it's definition and see what it does.

In VS 2015, for example for a View() in a Controller, I have to Right Click -> Go to Definition. But the definition is just this:

...
//
// Summary:
//     Creates a Microsoft.AspNetCore.Mvc.ViewResult object that renders a view to the
//     response.
//
// Returns:
//     The created Microsoft.AspNetCore.Mvc.ViewResult object for the response.
[NonAction]
public virtual ViewResult View();
...

So I can't see what it actually does. Is this because it's closed-source?

EDIT:

I installed the dotPeek free from Jetbrains and works awesome for what I was looking. It even has the Control-Click to go to definition:

https://www.jetbrains.com/decompiler/

JorgeeFG
  • 5,651
  • 12
  • 59
  • 92
  • 2
    Possible duplicate of [“Go To Definition” in Visual Studio only brings up the Metadata for Non-Project references](http://stackoverflow.com/q/13203346/1260204)? – Igor Aug 04 '16 at 14:08

2 Answers2

2

This isn't because it's closed-source, but rather the code within it has already been compiled and you are simply referencing it through a DLL (and you haven't explicitly loaded the symbols to debug through the actual source).

If you wanted to actually see the chain of method calls and what their source looks like, you can take a look at the ASP.NET Core MVC repository on GitHub or attempt to debug against the source itself as mentioned here.

Your Call Stack for the View() Method

If you wanted to know what actually is going on behind-the-scenes and didn't need to explicitly debug the source itself, you can follow along in the previously linked GitHub repo to see the following calls.

  • View() from Controller.cs

    • Accepts your parameters and passes them to another overload that explicitly takes View/Model parameters.
  • View(name, model) from Controller.cs

    • Builds a ViewResult object using the data from your parameters and the View you are targeting.
  • ViewResult() from ViewResult.cs

    • Pulls in necessary services and resolves the View location, then attempts to execute the action.
  • ExecuteAsync() from ViewResultExecutor.cs

    • Passes all context, view and data along and logs the request being made.
  • ExecuteAsync() from ViewExecutor.cs

    • Ensures that everything is correct and handles building the actual response and flushing it out to the user with the appropriate headers, content, etc.
Rion Williams
  • 74,820
  • 37
  • 200
  • 327
  • It's very difficult to navigate the repo, I miss the Go to Definition link lol. But this is somehow what I was looking for, thanks – JorgeeFG Aug 04 '16 at 15:41
  • Yeah, a Go to Definition option would be a really great feature for navigating large repos, but glad that this was helpful. – Rion Williams Aug 04 '16 at 15:42
  • One question, this uses ActionResult: https://github.com/aspnet/Mvc/blob/683356ea59170185044f167d1a2006e79d5ad86a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs but it doesn't include the file where it is defined: https://github.com/aspnet/Mvc/blob/d4c7dc3a834edc507865816a59960c5b31f9b10c/src/Microsoft.AspNetCore.Mvc.Core/ActionResult.cs how could it be located then? – JorgeeFG Aug 04 '16 at 15:55
  • Generally you would just want to do a search for the name of the class or interface. That's generally what I do, you can use some context regarding what you are searching for (i.e. you know that your existing `ViewResult` inherits from a class called `ActionResult`, so you can search for "class ActionResult"). Does that make sense? – Rion Williams Aug 04 '16 at 15:58
  • Yes, I see that it inherits from ActionResult, but what is making noise for me is that ActionResult resides in `src/Microsoft.AspNetCore.Mvc.Core` while ViewResult resides in `src/Microsoft.AspNetCore.Mvc.ViewFeatures` and in ViewResult.cs isn't an include like `using src/Microsoft.AspNetCore.Mvc.Core`, so, how dows it know that ViewResult is in Core and doesn't trhow compile error? – JorgeeFG Aug 04 '16 at 16:06
  • I see those files have the same Namespace, maybe because of that? But they reside in different directories. – JorgeeFG Aug 04 '16 at 16:09
1

Yes, you wont be able to see its implementation unless you reflect it with some tool like reflector.net.

Usually, the only code you can see is the one you have in your solution.

Leandro Galluppi
  • 915
  • 1
  • 7
  • 19