@@ -29,11 +29,11 @@ public class RatingPrompt
2929 /// <param name="requestsBeforePrompt">Indicates how many successful requests it takes before the user is prompted to rate.</param>
3030 /// <exception cref="ArgumentNullException">None of the parameters passed in can be null.</exception>
3131 /// <exception cref="ArgumentException">The Marketplace ID has to be valid so an absolute URI can be constructed.</exception>
32- public RatingPrompt ( string marketplaceId , string extensionName , IRatingConfig config , int requestsBeforePrompt = 5 )
32+ public RatingPrompt ( string marketplaceId , string extensionName , IRatingConfig ? config = null , int requestsBeforePrompt = 5 )
3333 {
3434 MarketplaceId = marketplaceId ?? throw new ArgumentNullException ( nameof ( marketplaceId ) ) ;
3535 ExtensionName = extensionName ?? throw new ArgumentNullException ( nameof ( extensionName ) ) ;
36- Config = config ?? throw new ArgumentNullException ( nameof ( config ) ) ;
36+ Config = config ;
3737 RequestsBeforePrompt = requestsBeforePrompt ;
3838
3939 string ratingUrl = string . Format ( CultureInfo . InvariantCulture , _urlFormat , MarketplaceId ) ;
@@ -59,7 +59,7 @@ public RatingPrompt(string marketplaceId, string extensionName, IRatingConfig co
5959 /// <summary>
6060 /// The configuration/options object used to store the information related to the rating prompt.
6161 /// </summary>
62- public virtual IRatingConfig Config { get ; }
62+ public virtual IRatingConfig ? Config { get ; }
6363
6464 /// <summary>
6565 /// The Marketplace URL the users are taken to when prompted.
@@ -77,6 +77,11 @@ public RatingPrompt(string marketplaceId, string extensionName, IRatingConfig co
7777 /// </summary>
7878 public virtual void RegisterSuccessfulUsage ( )
7979 {
80+ if ( Config == null )
81+ {
82+ throw new NullReferenceException ( "The Config property has not been set." ) ;
83+ }
84+
8085 if ( _hasAlreadyRequested . TryAdd ( MarketplaceId , true ) && Config . RatingRequests < RequestsBeforePrompt )
8186 {
8287 IncrementAsync ( ) . FireAndForget ( ) ;
@@ -89,15 +94,19 @@ public virtual void RegisterSuccessfulUsage()
8994 public virtual async Task ResetAsync ( )
9095 {
9196 _hasAlreadyRequested . TryRemove ( MarketplaceId , out _ ) ;
92- Config . RatingRequests = 0 ;
93- await Config . SaveAsync ( ) ;
97+
98+ if ( Config != null )
99+ {
100+ Config . RatingRequests = 0 ;
101+ await Config . SaveAsync ( ) ;
102+ }
94103 }
95104
96105 private async Task IncrementAsync ( )
97106 {
98107 await Task . Yield ( ) ; // Yield to allow any shutdown procedure to continue
99108
100- if ( VsShellUtilities . ShellIsShuttingDown )
109+ if ( VsShellUtilities . ShellIsShuttingDown || Config == null )
101110 {
102111 return ;
103112 }
@@ -111,7 +120,10 @@ private async Task IncrementAsync()
111120 }
112121 }
113122
114- private async Task PromptAsync ( )
123+ /// <summary>
124+ /// Prompts the user to rate the extension.
125+ /// </summary>
126+ public async Task PromptAsync ( )
115127 {
116128 InfoBar ? infoBar = await CreateInfoBarAsync ( ) ;
117129
0 commit comments