Skip to content

Commit 16e5ec4

Browse files
authored
Merge pull request #4 from d1820/bug-fix-nullabletype
Bug fix nullable DateTime
2 parents 879e202 + 58768b2 commit 16e5ec4

8 files changed

Lines changed: 108 additions & 11 deletions

File tree

CodeDocumentor.Test/PropertyUnitTests.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,22 @@ public class PropertyTester
182182
}
183183
}";
184184

185+
/// <summary>
186+
/// The nullable datetime property test code.
187+
/// </summary>
188+
private const string NullableDateTimePropertyTestCode = @"
189+
using System;
190+
using System.Collections.Generic;
191+
using System.Text;
192+
193+
namespace ConsoleApp4
194+
{
195+
public class PropertyTester
196+
{
197+
public DateTime? TestDateTime { get; set; }
198+
}
199+
}";
200+
185201
/// <summary>
186202
/// The boolean property test fix code.
187203
/// </summary>
@@ -217,6 +233,25 @@ public class PropertyTester
217233
}
218234
}";
219235

236+
/// <summary>
237+
/// The nullable date time property test fix code.
238+
/// </summary>
239+
private const string NullableDateTimePropertyTestFixCode = @"
240+
using System;
241+
using System.Collections.Generic;
242+
using System.Text;
243+
244+
namespace ConsoleApp4
245+
{
246+
public class PropertyTester
247+
{
248+
/// <summary>
249+
/// Gets or Sets a test date time
250+
/// </summary>
251+
public DateTime? TestDateTime { get; set; }
252+
}
253+
}";
254+
220255
/// <summary>
221256
/// The nullable boolean property test fix code.
222257
/// </summary>
@@ -307,7 +342,8 @@ public void NoDiagnosticsShow(string testCode)
307342
[DataRow(BooleanPropertyTestCode, BooleanPropertyTestFixCode, 10, 15)]
308343
[DataRow(NullableBooleanPropertyTestCode, NullableBooleanPropertyTestFixCode, 10, 16)]
309344
[DataRow(ExpressionBodyPropertyTestCode, ExpressionBodyPropertyTestFixCode, 10, 17)]
310-
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column)
345+
[DataRow(NullableDateTimePropertyTestCode, NullableDateTimePropertyTestFixCode, 10, 20)]
346+
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column)
311347
{
312348
var expected = new DiagnosticResult
313349
{

CodeDocumentor/Helper/CommentHelper.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime;
45
using CodeDocumentor.Vsix2022;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.CSharp;
@@ -20,6 +21,10 @@ public static class CommentHelper
2021
/// <returns> </returns>
2122
public static string WithPeriod(this string text)
2223
{
24+
if (text.EndsWith("."))
25+
{
26+
return text;
27+
}
2328
return text + ".";
2429
}
2530

@@ -123,8 +128,11 @@ public static string CreatePropertyComment(ReadOnlySpan<char> name, bool isBoole
123128
public static string CreateMethodComment(ReadOnlySpan<char> name, TypeSyntax returnType)
124129
{
125130
List<string> parts = SpilitNameAndToLower(name, false, false);
126-
127-
parts[0] = Pluralizer.Pluralize(parts[0]);
131+
var isBool2part = parts.Count == 2 && returnType.ToString().IndexOf("bool", StringComparison.InvariantCultureIgnoreCase) > -1;
132+
if (!isBool2part)
133+
{
134+
parts[0] = Pluralizer.Pluralize(parts[0]);
135+
}
128136
if (parts.Count == 1 || (parts.Count == 2 && parts.Last() == "asynchronously"))
129137
{
130138
parts.Insert(1, "the");
@@ -163,9 +171,13 @@ public static string CreateMethodComment(ReadOnlySpan<char> name, TypeSyntax ret
163171
}
164172
else
165173
{
166-
parts.Insert(1, "the");
174+
var skipThe = Constants.INTERNAL_SPECIAL_WORD_LIST.Any(w => w.Equals(parts[0]));
175+
if (!skipThe && !isBool2part)
176+
{
177+
parts.Insert(1, "the");
178+
}
167179
}
168-
180+
169181
return string.Join(" ", parts).Translate().WithPeriod();
170182
}
171183

CodeDocumentor/Helper/Pluralizer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using ThirdPartPluralizer = Pluralize.NET;
1+
using System.Linq;
2+
using CodeDocumentor.Vsix2022;
3+
using ThirdPartPluralizer = Pluralize.NET;
24

35
namespace CodeDocumentor.Helper
46
{
@@ -14,7 +16,13 @@ public static class Pluralizer
1416
/// <returns> A plural word. </returns>
1517
public static string Pluralize(string word)
1618
{
17-
return new ThirdPartPluralizer.Pluralizer().Pluralize(word);
19+
var skipPlural = Constants.INTERNAL_SPECIAL_WORD_LIST.Any(w => w.Equals(word));
20+
if (!skipPlural)
21+
{
22+
var pl = new ThirdPartPluralizer.Pluralizer();
23+
return pl.Pluralize(word);
24+
}
25+
return word;
1826
}
1927
}
2028
}

CodeDocumentor/Models/Constants.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public static class Constants
2121
new WordMap { Word = "OfCollection", Translation = "OfCollections" },
2222
new WordMap { Word = "IReadOnlyCollection", Translation = "Read Only Collection" },
2323
new WordMap { Word = "IReadOnlyDictionary", Translation = "Read Only Dictionary" },
24-
new WordMap { Word = "Shoulds the", Translation = "Should" },
2524
};
25+
26+
public static string[] INTERNAL_SPECIAL_WORD_LIST = new[] { "Should", "Would", "Could",
27+
"Ensure", "Can", "Why", "Welcome" };
2628
}
2729
}

CodeDocumentor/PropertyCodeFixProvider.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
8686
else if (declarationSyntax.Type.IsKind(SyntaxKind.NullableType))
8787
{
8888
var returnType = ((NullableTypeSyntax)declarationSyntax.Type).ElementType as PredefinedTypeSyntax;
89-
isBoolean = returnType.ToString().IndexOf("bool", StringComparison.OrdinalIgnoreCase) > -1;
89+
if(returnType != null)
90+
{
91+
isBoolean = returnType.ToString().IndexOf("bool", StringComparison.OrdinalIgnoreCase) > -1;
92+
}
9093
}
9194

9295
bool hasSetter = false;

Manifests/vs2022/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="CodeDocumentor.2022.88F29096-CA4C-4F88-A260-705D8BBFCF2A" Version="1.1" Language="en-US" Publisher="Dan Turco"/>
4+
<Identity Id="CodeDocumentor.2022.88F29096-CA4C-4F88-A260-705D8BBFCF2A" Version="1.1.2" Language="en-US" Publisher="Dan Turco"/>
55
<DisplayName>CodeDocumentor</DisplayName>
66
<Description xml:space="preserve">An Extension to generate XML documentation automatically using IntelliSense for interface,class,enum, field, constructor, property and method.</Description>
77
<Icon>logo.png</Icon>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using ProtoBuf;
2+
namespace Sample;
3+
4+
[ProtoContract]
5+
public class protoTester
6+
{
7+
[ProtoMember(1)]
8+
public int MyProperty { get; set; }
9+
10+
[ProtoMember(2)]
11+
public int MyProperty1 { get; set; }
12+
13+
public DateTime? NullDateTime { get; set; }
14+
15+
public int? NullInt { get; set; }
16+
17+
public int?[] NullIntArray { get; set; }
18+
19+
public bool CanExecute() { return true; }
20+
21+
public bool ShouldHappen() { return true; }
22+
}
23+
24+
namespace Sample.Other
25+
{
26+
27+
[ProtoContract]
28+
public class protoTester
29+
{
30+
[ProtoMember(1)]
31+
public int MyProperty { get; set; }
32+
33+
[ProtoMember(2)]
34+
public int MyProperty1 { get; set; }
35+
}
36+
}

0 commit comments

Comments
 (0)