Skip to content

Commit

Permalink
fixed string and char const field definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Doraku committed Jun 16, 2022
1 parent 84a2aee commit 6d26601
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 9 deletions.
3 changes: 3 additions & 0 deletions documentation/NEXT_RELEASENOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Bug fixes

- fixed string and char const field definition
7 changes: 6 additions & 1 deletion source/DefaultDocumentation.Markdown/Elements/CElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class CElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "c";

/// <inheritdoc/>
public string Name => "c";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
7 changes: 6 additions & 1 deletion source/DefaultDocumentation.Markdown/Elements/CodeElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class CodeElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "code";

private static string GetCode(ISettings settings, string source, string? region = null)
{
if (!Path.IsPathRooted(source) && settings.ProjectDirectory != null)
Expand Down Expand Up @@ -39,7 +44,7 @@ private static string GetCode(ISettings settings, string source, string? region
}

/// <inheritdoc/>
public string Name => "code";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
7 changes: 6 additions & 1 deletion source/DefaultDocumentation.Markdown/Elements/ListElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class ListElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "list";

private static void WriteItem(IWriter writer, XElement element)
{
XElement? term = element.GetTerm();
Expand Down Expand Up @@ -109,7 +114,7 @@ private static void WriteTable(IWriter writer, XElement element)
}

/// <inheritdoc/>
public string Name => "list";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
7 changes: 6 additions & 1 deletion source/DefaultDocumentation.Markdown/Elements/NoteElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class NoteElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "note";

/// <inheritdoc/>
public string Name => "note";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
7 changes: 6 additions & 1 deletion source/DefaultDocumentation.Markdown/Elements/ParaElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class ParaElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "para";

/// <inheritdoc/>
public string Name => "para";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class ParamRefElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "paramref";

/// <inheritdoc/>
public string Name => "paramref";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
7 changes: 6 additions & 1 deletion source/DefaultDocumentation.Markdown/Elements/SeeElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class SeeElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "see";

/// <inheritdoc/>
public string Name => "see";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ namespace DefaultDocumentation.Markdown.Elements
/// </summary>
public sealed class TypeParamRefElement : IElement
{
/// <summary>
/// The name of this implementation used at the configuration level.
/// </summary>
public const string ConfigName = "typeparamref";

/// <inheritdoc/>
public string Name => "typeparamref";
public string Name => ConfigName;

/// <inheritdoc/>
public void Write(IWriter writer, XElement element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,28 @@ static IWriter Write(IWriter writer, Action<IWriter> writeAction)

_ = writer.GetCurrentItem() switch
{
FieldDocItem item => Write(writer, w => w.Append($"{_fieldAmbience.ConvertSymbol(item.Field)}{(item.Field.IsConst ? $" = {item.Field.GetConstantValue()}" : string.Empty)};")),
FieldDocItem item => Write(writer, w =>
{
w.Append(_fieldAmbience.ConvertSymbol(item.Field));

if (item.Field.IsConst)
{
string typeDelimiter =
item.Field.Type.IsKnownType(KnownTypeCode.String)
? "\""
: item.Field.Type.IsKnownType(KnownTypeCode.Char)
? "'"
: string.Empty;

w
.Append(" = ")
.Append(typeDelimiter)
.Append($"{item.Field.GetConstantValue()}")
.Append(typeDelimiter);
}

w.Append(";");
}),
PropertyDocItem item => Write(writer, w => w.Append(_propertyAmbience.ConvertSymbol(item.Property))),
EventDocItem item => Write(writer, w => w.Append(_eventAmbience.ConvertSymbol(item.Event))),
ConstructorDocItem item => Write(writer, w => w.Append(_methodAmbience.ConvertSymbol(item.Method)).Append(";")),
Expand Down
6 changes: 6 additions & 0 deletions source/DefaultDocumentation.Test/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ private static class ClassWithTypeParameter<T>

private const int _constField = 42;

private const string _constStringField = "string";

private const char _constCharField = 'e';

#pragma warning disable CS0649
private static readonly int _field;
#pragma warning restore CS0649
Expand Down Expand Up @@ -107,6 +111,8 @@ void IInterface.Method()
public static readonly ClassDocItem ClassDocItem = new(NamespaceDocItem, Get<ITypeDefinition>($"T:{typeof(AssemblyInfo).FullName}"), null);
public static readonly EventDocItem EventDocItem = new(ClassDocItem, Get<IEvent>($"E:{typeof(AssemblyInfo).FullName}.{nameof(Event)}"), null);
public static readonly FieldDocItem ConstFieldDocItem = new(ClassDocItem, Get<IField>($"F:{typeof(AssemblyInfo).FullName}.{nameof(_constField)}"), null);
public static readonly FieldDocItem ConstStringFieldDocItem = new(ClassDocItem, Get<IField>($"F:{typeof(AssemblyInfo).FullName}.{nameof(_constStringField)}"), null);
public static readonly FieldDocItem ConstCharFieldDocItem = new(ClassDocItem, Get<IField>($"F:{typeof(AssemblyInfo).FullName}.{nameof(_constCharField)}"), null);
public static readonly FieldDocItem FieldDocItem = new(ClassDocItem, Get<IField>($"F:{typeof(AssemblyInfo).FullName}.{nameof(_field)}"), null);
public static readonly PropertyDocItem PropertyDocItem = new(ClassDocItem, Get<IProperty>($"P:{typeof(AssemblyInfo).FullName}.{nameof(Property)}"), null);
public static readonly MethodDocItem MethodWithGenericConstrainsDocItem = new(ClassDocItem, Get<IMethod>($"M:{typeof(AssemblyInfo).FullName}.{nameof(MethodWithGenericConstrains)}``5"), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ public void Write_should_write_When_FieldDocItem_and_constant() => Test(
AssemblyInfo.ConstFieldDocItem,
@"```csharp
private const int _constField = 42;
```");

[Fact]
public void Write_should_write_When_FieldDocItem_and_constant_string() => Test(
AssemblyInfo.ConstStringFieldDocItem,
@"```csharp
private const string _constStringField = ""string"";
```");

[Fact]
public void Write_should_write_When_FieldDocItem_and_constant_char() => Test(
AssemblyInfo.ConstCharFieldDocItem,
@"```csharp
private const char _constCharField = 'e';
```");

[Fact]
Expand Down

0 comments on commit 6d26601

Please sign in to comment.