Skip to content

Commit 1dc5faf

Browse files
RazorCodeDocument: Convert Get/SetFileKind to instance methods
Move the GetFileKind and SetFileKind extension methods to RazorCodeDocument and make them instance methods backed by a simple field.
1 parent c0bd75d commit 1dc5faf

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public sealed class RazorCodeDocument
1515
public RazorParserOptions ParserOptions { get; }
1616
public RazorCodeGenerationOptions CodeGenerationOptions { get; }
1717

18+
private string? _fileKind;
19+
1820
private RazorCodeDocument(
1921
RazorSourceDocument source,
2022
ImmutableArray<RazorSourceDocument> imports,
@@ -50,4 +52,12 @@ public static RazorCodeDocument Create(
5052

5153
return new RazorCodeDocument(source, imports, parserOptions, codeGenerationOptions);
5254
}
55+
56+
public string? GetFileKind()
57+
=> _fileKind;
58+
59+
public void SetFileKind(string fileKind)
60+
{
61+
_fileKind = fileKind;
62+
}
5363
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocumentExtensions.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,26 +202,6 @@ public static void SetCSharpDocument(this RazorCodeDocument document, RazorCShar
202202
document.Items[typeof(RazorCSharpDocument)] = csharp;
203203
}
204204

205-
public static string GetFileKind(this RazorCodeDocument document)
206-
{
207-
if (document == null)
208-
{
209-
throw new ArgumentNullException(nameof(document));
210-
}
211-
212-
return (string)document.Items[typeof(FileKinds)];
213-
}
214-
215-
public static void SetFileKind(this RazorCodeDocument document, string fileKind)
216-
{
217-
if (document == null)
218-
{
219-
throw new ArgumentNullException(nameof(document));
220-
}
221-
222-
document.Items[typeof(FileKinds)] = fileKind;
223-
}
224-
225205
public static string GetCssScope(this RazorCodeDocument document)
226206
{
227207
if (document == null)

src/Razor/test/Microsoft.VisualStudio.LegacyEditor.Razor.Test/Parsing/VisualStudioRazorParserIntegrationTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public async Task NoDocumentSnapshotParsesComponentFileCorrectly()
6060
Assert.Equal(1, manager._parseCount);
6161

6262
var codeDocument = await manager.InnerParser.GetLatestCodeDocumentAsync(snapshot);
63+
Assert.NotNull(codeDocument);
6364
Assert.Equal(FileKinds.Component, codeDocument.GetFileKind());
6465

6566
// @code is only applicable in component files so we're verifying that `@code` was treated as a directive.

0 commit comments

Comments
 (0)