@@ -36,16 +36,11 @@ namespace DSharpPlusDocs.Rest
3636 public class GithubRest
3737 {
3838 private const string ApiUrl = "https://api.github.com" ;
39- private const string AcceptHeader = "application/vnd.github.v3+json" ;
40-
4139 private static async Task < JObject > SendRequestAsync ( HttpMethod method , string endpoint , string extra = null , string acceptHeader = null )
4240 {
4341 using HttpClient http = new ( ) ;
4442 HttpRequestMessage request = new ( method , $ "{ ApiUrl } { endpoint } { extra } ") ;
45- if ( acceptHeader == null )
46- {
47- acceptHeader = "application/vnd.github.v3+json" ;
48- }
43+ acceptHeader ??= "application/vnd.github.v3+json" ;
4944
5045 request . Headers . Add ( "Accept" , acceptHeader ) ;
5146 request . Headers . Add ( "User-Agent" , "DSharpPlus Docs Bot/1.0" ) ;
@@ -89,20 +84,20 @@ private static async Task<List<GitSearchResult>> SearchAsync(string search, stri
8984 public static async Task < string > GetTypeUrlAsync ( TypeInfoWrapper type )
9085 {
9186 List < GitSearchResult > search = await SearchAsync ( type . Name , $ "{ type . Name } .cs") ;
92- return search . FirstOrDefault ( x => x . Name == $ "{ type . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ?? null ; //null = Not found
87+ return search . Find ( x => x . Name == $ "{ type . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ?? null ; //null = Not found
9388 }
9489
9590 public static async Task < string > GetEventUrlAsync ( EventInfoWrapper ev )
9691 {
9792 List < GitSearchResult > search = await SearchAsync ( ev . Parent . Name , $ "{ ev . Parent . Name } .cs") ;
98- string result = search . FirstOrDefault ( x => x . Name == $ "{ ev . Parent . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ;
93+ string result = search . Find ( x => x . Name == $ "{ ev . Parent . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ;
9994 if ( result != null )
10095 {
10196 using HttpClient client = new ( ) ;
10297 string url = result . Replace ( "/blob/" , "/raw/" ) ;
10398 string code = await client . GetStringAsync ( url ) ;
10499 Microsoft . CodeAnalysis . SyntaxTree tree = CSharpSyntaxTree . ParseText ( code ) ;
105- CompilationUnitSyntax root = ( CompilationUnitSyntax ) tree . GetRoot ( ) ;
100+ CompilationUnitSyntax root = ( CompilationUnitSyntax ) await tree . GetRootAsync ( ) ;
106101 EventDeclarationSyntax source = root . DescendantNodes ( ) . OfType < EventDeclarationSyntax > ( ) . FirstOrDefault ( x => x . Identifier . ValueText == ev . Event . Name ) ;
107102 if ( source == null )
108103 {
@@ -119,14 +114,14 @@ public static async Task<string> GetEventUrlAsync(EventInfoWrapper ev)
119114 public static async Task < string > GetMethodUrlAsync ( MethodInfoWrapper method )
120115 {
121116 List < GitSearchResult > search = await SearchAsync ( method . Method . Name , $ "{ method . Parent . Name } .cs") ;
122- string result = search . FirstOrDefault ( x => x . Name == $ "{ method . Parent . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ;
117+ string result = search . Find ( x => x . Name == $ "{ method . Parent . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ;
123118 if ( result != null )
124119 {
125120 using HttpClient client = new ( ) ;
126121 string url = result . Replace ( "/blob/" , "/raw/" ) ;
127122 string code = await client . GetStringAsync ( url ) ;
128123 Microsoft . CodeAnalysis . SyntaxTree tree = CSharpSyntaxTree . ParseText ( code ) ;
129- CompilationUnitSyntax root = ( CompilationUnitSyntax ) tree . GetRoot ( ) ;
124+ CompilationUnitSyntax root = ( CompilationUnitSyntax ) await tree . GetRootAsync ( ) ;
130125 MethodDeclarationSyntax source = root . DescendantNodes ( ) . OfType < MethodDeclarationSyntax > ( ) . FirstOrDefault ( x => x . Identifier . ValueText == method . Method . Name ) ;
131126 if ( source == null )
132127 {
@@ -143,14 +138,14 @@ public static async Task<string> GetMethodUrlAsync(MethodInfoWrapper method)
143138 public static async Task < string > GetPropertyUrlAsync ( PropertyInfoWrapper property )
144139 {
145140 List < GitSearchResult > search = await SearchAsync ( property . Property . Name , $ "{ property . Parent . Name } .cs") ;
146- string result = search . FirstOrDefault ( x => x . Name == $ "{ property . Parent . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ;
141+ string result = search . Find ( x => x . Name == $ "{ property . Parent . Name } .cs") ? . HtmlUrl ?? search . FirstOrDefault ( ) ? . HtmlUrl ;
147142 if ( result != null )
148143 {
149144 using HttpClient client = new ( ) ;
150145 string url = result . Replace ( "/blob/" , "/raw/" ) ;
151146 string code = await client . GetStringAsync ( url ) ;
152147 Microsoft . CodeAnalysis . SyntaxTree tree = CSharpSyntaxTree . ParseText ( code ) ;
153- CompilationUnitSyntax root = ( CompilationUnitSyntax ) tree . GetRoot ( ) ;
148+ CompilationUnitSyntax root = ( CompilationUnitSyntax ) await tree . GetRootAsync ( ) ;
154149 PropertyDeclarationSyntax source = root . DescendantNodes ( ) . OfType < PropertyDeclarationSyntax > ( ) . FirstOrDefault ( x => x . Identifier . ValueText == property . Property . Name ) ;
155150 if ( source == null )
156151 {
0 commit comments