winget-cli

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

ClassModel.cs (1784B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 
      4 namespace Microsoft.Management.Deployment.Projection
      5 {
      6     using System;
      7     using System.Collections.Generic;
      8 
      9     public enum ClsidContext
     10     {
     11         // In process
     12         InProc,
     13 
     14         // Out of process production
     15         OutOfProc,
     16 
     17         // Out of process development
     18         OutOfProcDev
     19     }
     20 
     21     internal class ClassModel
     22     {
     23         /// <summary>
     24         /// Interface type corresponding to the object's IID
     25         /// </summary>
     26         public Type InterfaceType { init;  get; }
     27 
     28         /// <summary>
     29         /// Projected class type by CsWinRT
     30         /// </summary>
     31         public Type ProjectedClassType { init;  get; }
     32 
     33         /// <summary>
     34         /// Clsids for each context (e.g. InProc, OutOfProc, OutOfProcDev)
     35         /// </summary>
     36         public IReadOnlyDictionary<ClsidContext, Guid> Clsids { init; get; }
     37 
     38         /// <summary>
     39         /// Get CLSID based on the provided context
     40         /// </summary>
     41         /// <param name="context">Context</param>
     42         /// <returns>CLSID for the provided context, or throw an exception if not found.</returns>
     43         /// <exception cref="InvalidOperationException"></exception>
     44         public Guid GetClsid(ClsidContext context)
     45         {
     46             if (!Clsids.TryGetValue(context, out Guid clsid))
     47             {
     48                 throw new InvalidOperationException($"{ProjectedClassType.FullName} is not implemented in context {context}");
     49             }
     50 
     51             return clsid;
     52         }
     53 
     54         /// <summary>
     55         /// Get IID corresponding to the COM object
     56         /// </summary>
     57         /// <returns>IID.</returns>
     58         public Guid GetIid()
     59         {
     60             return InterfaceType.GUID;
     61         }
     62     }
     63 }