Skip to content

Commit 3e17f63

Browse files
SimonCroppyufeih
andauthored
chore: use some pattern matching (#10285)
* use some pattern matching * fix build failure --------- Co-authored-by: Yufei Huang <yufeih@live.com>
1 parent f06a6e9 commit 3e17f63

File tree

37 files changed

+51
-53
lines changed

37 files changed

+51
-53
lines changed

src/Docfx.App/Helpers/DocumentBuilderWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void BuildDocument(BuildJsonConfig config, BuildOptions options, T
2323
// Ensure "_enableSearch" adds the right post processor
2424
if (metadata != null && metadata.TryGetValue("_enableSearch", out object value))
2525
{
26-
if (value is bool isSearchable && isSearchable && !postProcessorNames.Contains("ExtractSearchIndex"))
26+
if (value is true && !postProcessorNames.Contains("ExtractSearchIndex"))
2727
{
2828
postProcessorNames = postProcessorNames.Add("ExtractSearchIndex");
2929
}

src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/BaseModelAttributeHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public object Handle(object obj, HandleModelAttributesContext context)
7878

7979
protected virtual bool ShouldHandle(object currentObj, object declaringObject, PropInfo currentPropInfo, HandleModelAttributesContext context)
8080
{
81-
return currentPropInfo != null && currentPropInfo.Attr != null;
81+
return currentPropInfo is {Attr: not null};
8282
}
8383

8484
/// <summary>

src/Docfx.Build.ManagedReference/BuildOutputs/ApiReferenceBuildOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void Expand(Dictionary<string, ApiReferenceBuildOutput> references, strin
300300

301301
public static List<ApiLanguageValuePair> GetSpecNames(string xref, string[] supportedLanguages, SortedList<string, List<SpecViewModel>> specs = null)
302302
{
303-
if (specs != null && specs.Count > 0)
303+
if (specs is {Count: > 0})
304304
{
305305
return (from spec in specs
306306
where supportedLanguages.Contains(spec.Key)

src/Docfx.Build.RestApi/BuildRestApiDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private static void MarkupRecursive(JToken jToken, IHostService host, FileModel
102102
{
103103
if (MarkupKeys.Contains(pair.Key) && pair.Value != null)
104104
{
105-
if (pair.Value is JValue jValue && jValue.Type == JTokenType.String)
105+
if (pair.Value is JValue {Type: JTokenType.String} jValue)
106106
{
107107
jObject[pair.Key] = Markup(host, (string)jValue, model, filter);
108108
}

src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private static bool IsSwaggerFile(string filePath)
211211
if (jObject.TryGetValue("swagger", out JToken swaggerValue))
212212
{
213213
var swaggerString = (string)swaggerValue;
214-
if (swaggerString != null && swaggerString.Equals("2.0"))
214+
if (swaggerString is "2.0")
215215
{
216216
return true;
217217
}

src/Docfx.Build.SchemaDriven/Models/JsonPointer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public JsonPointer GetParentPointer()
4949
public static bool TryCreate(string raw, out JsonPointer pointer)
5050
{
5151
pointer = null;
52-
if (raw != null && raw.Length > 0 && raw[0] != '/')
52+
if (raw is {Length: > 0} && raw[0] != '/')
5353
{
5454
return false;
5555
}

src/Docfx.Build.SchemaDriven/Processors/FileInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public FileInterpreter(bool exportFileLink, bool updateValue)
1919

2020
public bool CanInterpret(BaseSchema schema)
2121
{
22-
return schema != null && schema.ContentType == ContentType.File;
22+
return schema is {ContentType: ContentType.File};
2323
}
2424

2525
public object Interpret(BaseSchema schema, object value, IProcessContext context, string path)

src/Docfx.Build.SchemaDriven/Processors/HrefInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public HrefInterpreter(bool exportFileLink, bool updateValue, string siteHostNam
2121

2222
public bool CanInterpret(BaseSchema schema)
2323
{
24-
return schema != null && schema.ContentType == ContentType.Href;
24+
return schema is {ContentType: ContentType.Href};
2525
}
2626

2727
public object Interpret(BaseSchema schema, object value, IProcessContext context, string path)

src/Docfx.Build.SchemaDriven/Processors/MarkdownInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class MarkdownInterpreter : IInterpreter
99
{
1010
public bool CanInterpret(BaseSchema schema)
1111
{
12-
return schema != null && schema.ContentType == ContentType.Markdown;
12+
return schema is {ContentType: ContentType.Markdown};
1313
}
1414

1515
public object Interpret(BaseSchema schema, object value, IProcessContext context, string path)

src/Docfx.Build.SchemaDriven/Processors/XrefInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public XrefInterpreter(bool aggregateXrefs, bool resolveXref)
1919

2020
public bool CanInterpret(BaseSchema schema)
2121
{
22-
return schema != null && schema.ContentType == ContentType.Xref;
22+
return schema is {ContentType: ContentType.Xref};
2323
}
2424

2525
public object Interpret(BaseSchema schema, object value, IProcessContext context, string path)

0 commit comments

Comments
 (0)