CodeOwnersFile Class
Represents a parsed CODEOWNERS file.
var file = CodeOwnersFile.Parse("* @user1\n*.js @js-owner", CodeOwnersDialect.GitHub);
Assert.Equal("*", file.Entries[0].Pattern);
Assert.Equal("@user1", file.Entries[0].Owners[0].ToString());
Assert.Equal("*.js", file.Entries[1].Pattern);
Assert.Equal("@js-owner", file.Entries[1].Owners[0].ToString());public sealed class CodeOwnersFileRemarks
An instance only exists for a valid file: CodeOwnersFile.Parse throws and CodeOwnersFile.TryParse returns false rather than returning a partially parsed file.
Properties
| Name | Description |
|---|---|
| Entries | Gets the entries of the file, in the order they appear in it. |
Entries
CodeOwnersFile.csGets the entries of the file, in the order they appear in it.
public IReadOnlyList<CodeOwnersEntry> Entries { get; }Property value
IReadOnlyList<CodeOwnersEntry>
Remarks
CODEOWNERS resolution is last-match-wins, so the last entry whose CodeOwnersEntry.Pattern matches a path owns it.
Methods
| Name | Description |
|---|---|
| Parse(ReadOnlySpan<char>, CodeOwnersDialect) | Parses the content of a CODEOWNERS file. |
| Parse(string, CodeOwnersDialect) | Parses the content of a CODEOWNERS file. |
| TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?) | Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid. |
| TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError) | Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid. |
| TryParse(string, CodeOwnersDialect, CodeOwnersFile?) | Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid. |
| TryParse(string, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError) | Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid. |
Parse overloads
Parse(ReadOnlySpan<char>, CodeOwnersDialect)
CodeOwnersFile.csParses the content of a CODEOWNERS file.
public static CodeOwnersFile Parse(ReadOnlySpan<char> content, CodeOwnersDialect dialect)Parameters
contentReadOnlySpan<char>- The content of the CODEOWNERS file.
dialectCodeOwnersDialect- The syntax
contentuses. Sections are only recognized byCodeOwnersDialect.GitLab.
Returns
CodeOwnersFile The parsed CodeOwnersFile.
Exceptions
CodeOwnersParseExceptioncontentis not a valid CODEOWNERS file. Parsing stops at the first error.
Remarks
The returned CodeOwnersFile does not reference content: every value it exposes is copied out of it.
Parse(string, CodeOwnersDialect)
CodeOwnersFile.csParses the content of a CODEOWNERS file.
public static CodeOwnersFile Parse(string content, CodeOwnersDialect dialect)Parameters
contentstring- The content of the CODEOWNERS file.
dialectCodeOwnersDialect- The syntax
contentuses. Sections are only recognized byCodeOwnersDialect.GitLab.
Returns
CodeOwnersFile The parsed CodeOwnersFile.
Exceptions
CodeOwnersParseExceptioncontentis not a valid CODEOWNERS file. Parsing stops at the first error.
TryParse overloads
TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?)
CodeOwnersFile.csParses the content of a CODEOWNERS file and returns a value indicating whether it is valid.
public static bool TryParse(ReadOnlySpan<char> content, CodeOwnersDialect dialect, out CodeOwnersFile? file)Parameters
contentReadOnlySpan<char>- The content of the CODEOWNERS file.
dialectCodeOwnersDialect- The syntax
contentuses. Sections are only recognized byCodeOwnersDialect.GitLab. fileCodeOwnersFile?- When this method returns
true, contains the parsedCodeOwnersFile; otherwise,null.
Returns
bool true when content is a valid CODEOWNERS file; otherwise, false.
Remarks
Use the CodeOwnersFile.TryParse overload to know why the file is invalid.
TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError)
CodeOwnersFile.csParses the content of a CODEOWNERS file and returns a value indicating whether it is valid.
public static bool TryParse(ReadOnlySpan<char> content, CodeOwnersDialect dialect, out CodeOwnersFile? file, out CodeOwnersParseError error)Parameters
contentReadOnlySpan<char>- The content of the CODEOWNERS file.
dialectCodeOwnersDialect- The syntax
contentuses. Sections are only recognized byCodeOwnersDialect.GitLab. fileCodeOwnersFile?- When this method returns
true, contains the parsedCodeOwnersFile; otherwise,null. errorCodeOwnersParseError- When this method returns
false, contains the first error found incontent; otherwise,default.
Returns
bool true when content is a valid CODEOWNERS file; otherwise, false.
Remarks
The parsed CodeOwnersFile does not reference content: every value it exposes is copied out of it.
TryParse(string, CodeOwnersDialect, CodeOwnersFile?)
CodeOwnersFile.csParses the content of a CODEOWNERS file and returns a value indicating whether it is valid.
public static bool TryParse(string content, CodeOwnersDialect dialect, out CodeOwnersFile? file)Parameters
contentstring- The content of the CODEOWNERS file.
dialectCodeOwnersDialect- The syntax
contentuses. Sections are only recognized byCodeOwnersDialect.GitLab. fileCodeOwnersFile?- When this method returns
true, contains the parsedCodeOwnersFile; otherwise,null.
Returns
bool true when content is a valid CODEOWNERS file; otherwise, false.
Remarks
Use the CodeOwnersFile.TryParse overload to know why the file is invalid.
TryParse(string, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError)
CodeOwnersFile.csParses the content of a CODEOWNERS file and returns a value indicating whether it is valid.
public static bool TryParse(string content, CodeOwnersDialect dialect, out CodeOwnersFile? file, out CodeOwnersParseError error)Parameters
contentstring- The content of the CODEOWNERS file.
dialectCodeOwnersDialect- The syntax
contentuses. Sections are only recognized byCodeOwnersDialect.GitLab. fileCodeOwnersFile?- When this method returns
true, contains the parsedCodeOwnersFile; otherwise,null. errorCodeOwnersParseError- When this method returns
false, contains the first error found incontent; otherwise,default.
Returns
bool true when content is a valid CODEOWNERS file; otherwise, false.