Jim S
Jim S

Reputation: 1079

How do I get the xml documentation generated from c# to appear in alphabetical order?

I am writing a web service using Microsoft Web API Controller classes (v2.1) and using XML at the beginning of each class and method to automatically generate the documentation. The generated documentation has a home page listing each class and method with a link to see more details.

Unfortunately, this home (or index) page shows the classes in what appears to me to be a random order, making it hard to find the classes you want.

Is there a way to get them to appear in alphabetical order?

Upvotes: 3

Views: 416

Answers (1)

Jim S
Jim S

Reputation: 1079

In folder Areas\HelpPage\Views\Help is a file named index.cshtml which is the template for generating the help documentation. It contains the following code that generates the home page:

<section class="content-wrapper main-content clear-fix">
    @foreach (var group in apiGroups) {
        @Html.DisplayFor(m => group, "ApiGroup")
    }
</section>

The classes can be placed in alphabetical order by inserting one line before the @foreach and making one change in the @foreach line, as follows:

<section class="content-wrapper main-content clear-fix">
    @{var orderedGroups = (from g in apiGroups orderby g.Key.ControllerName select g).ToArray();}
    @foreach (var group in orderedGroups) {
        @Html.DisplayFor(m => group, "ApiGroup")
    }
</section>

The new line simply sorts the classes before generating the home page.

Upvotes: 1

Related Questions