winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ValueSetExtensions.cs (1161B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="ValueSetExtensions.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.WinGet.Configuration.Engine.Extensions
      8 {
      9     using Windows.Foundation.Collections;
     10 
     11     /// <summary>
     12     /// Extension methods for Value set.
     13     /// </summary>
     14     internal static class ValueSetExtensions
     15     {
     16         /// <summary>
     17         /// Gets the string value of a given key.
     18         /// Null is doesn't exist or cast can't be done.
     19         /// </summary>
     20         /// <param name="valueSet">Value set.</param>
     21         /// <param name="key">Key.</param>
     22         /// <returns>String value.</returns>
     23         public static string? TryGetStringValue(this ValueSet valueSet, string key)
     24         {
     25             if (valueSet.TryGetValue(key, out object value))
     26             {
     27                 return value as string;
     28             }
     29 
     30             return null;
     31         }
     32     }
     33 }