@@ -47,11 +47,18 @@ public FormatUtilities(IOptions<ImageSharpMiddlewareOptions> options)
4747 /// Gets the file extension for the given image uri.
4848 /// </summary>
4949 /// <param name="uri">The full request uri.</param>
50- /// <returns>The <see cref="string" />.</returns>
50+ /// <param name="extension">
51+ /// When this method returns, contains the file extension for the image source,
52+ /// if the path exists; otherwise, the default value for the type of the path parameter.
53+ /// This parameter is passed uninitialized.
54+ /// </param>
55+ /// <returns>
56+ /// <see langword="true" /> if the uri contains an extension; otherwise, <see langword="false" />.
57+ /// </returns>
5158 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
52- public string GetExtensionFromUri ( string uri )
59+ public bool TryGetExtensionFromUri ( string uri , out string extension )
5360 {
54- // TODO: This method should follow TryGet pattern. Fix for V2.
61+ extension = null ;
5562 int query = uri . IndexOf ( '?' ) ;
5663 ReadOnlySpan < char > path ;
5764
@@ -62,15 +69,16 @@ public string GetExtensionFromUri(string uri)
6269 {
6370 // We have a query but is it a valid one?
6471 ReadOnlySpan < char > extSpan = ext [ 0 ] . AsSpan ( ) ;
65- foreach ( string extension in this . extensions )
72+ foreach ( string e in this . extensions )
6673 {
67- if ( extSpan . Equals ( extension , StringComparison . OrdinalIgnoreCase ) )
74+ if ( extSpan . Equals ( e , StringComparison . OrdinalIgnoreCase ) )
6875 {
69- return extension ;
76+ extension = e ;
77+ return true ;
7078 }
7179 }
7280
73- return null ;
81+ return false ;
7482 }
7583
7684 path = uri . AsSpan ( 0 , query ) ;
@@ -85,16 +93,17 @@ public string GetExtensionFromUri(string uri)
8593 {
8694 ReadOnlySpan < char > pathExtension = path . Slice ( extensionIndex + 1 ) ;
8795
88- foreach ( string extension in this . extensions )
96+ foreach ( string e in this . extensions )
8997 {
90- if ( pathExtension . Equals ( extension , StringComparison . OrdinalIgnoreCase ) )
98+ if ( pathExtension . Equals ( e , StringComparison . OrdinalIgnoreCase ) )
9199 {
92- return extension ;
100+ extension = e ;
101+ return true ;
93102 }
94103 }
95104 }
96105
97- return null ;
106+ return false ;
98107 }
99108
100109 /// <summary>
0 commit comments