dotnet / dotnet/docfx

[Feature Request] Default values of properties and fields in API reference

Open
#10,240 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.4k
Forks
890
Avg merge
2h 9m
Merged PRs (30d)
11

Description

**Is your feature request related to a problem? Please describe.**
The problem is that generated API reference currently shows no information about the default value of a property/field.
By default I mean the value set using inline initializers. I'm not interested in the bodies of constructors being parsed.

Example 0

For the following code:
```cs
public string TEST = "test field";
public string TEST2 { get; set; } = "test property";
```
the generated content looks like this:
## Fields
### TEST
```cs
public string TEST
```
#### Field Value
[string](https://learn.microsoft.com/dotnet/api/system.string)
## Properties
### TEST2
```cs
public string TEST2 { get; set; }
```
#### Property Value
[string](https://learn.microsoft.com/dotnet/api/system.string)

**Describe the solution you'd like**
I'd like for that information to appear in docs. It could be put in the code block mirroring the property/field declaration (Example 1) or as a subsection of the "Property Value"/"Field Value" entries (Example 2).

Example 1

For the following code:
```cs
public string TEST = "test field";
public string TEST2 { get; set; } = "test property";
```
the generated content could look like this:
## Fields
### TEST
```cs
public string TEST = "test field";
```
#### Field Value
[string](https://learn.microsoft.com/dotnet/api/system.string)
## Properties
### TEST2
```cs
public string TEST2 { get; set; } = "test property";
```
#### Property Value
[string](https://learn.microsoft.com/dotnet/api/system.string)

Example 2

For the following code:
```cs
public string TEST = "test field";
public string TEST2 { get; set; } = "test property";
```
the generated content could look like this:
## Fields
### TEST
```cs
public string TEST
```
#### Field Value
[string](https://learn.microsoft.com/dotnet/api/system.string)
##### Default Value
`"test field"`
## Properties
### TEST2
```cs
public string TEST2 { get; set; }
```
#### Property Value
[string](https://learn.microsoft.com/dotnet/api/system.string)
##### Default Value
`"test property"`

**Describe alternatives you've considered**
Putting the default value in a custom description in tag `` tag (Example 3).
Unfortunately, such a duplication makes desynchronization between the code and the documentation very likely to occur.

Example 3

For the following code:
```cs
/// Default value: "test field"
public string TEST = "test field";
/// Default value: "test property"
public string TEST2 { get; set; } = "test property";
```
the generated content could look like this:
## Fields
### TEST
```cs
public string TEST
```
#### Field Value
[string](https://learn.microsoft.com/dotnet/api/system.string)
> Default value: "test field"
## Properties
### TEST2
```cs
public string TEST2 { get; set; }
```
#### Property Value
[string](https://learn.microsoft.com/dotnet/api/system.string)
> Default value: "test property"

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.