The Labs \ Source Viewer \ SSCLI \ System.ComponentModel.Design \ CommandID

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CommandID.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. /*
  16. */
  17. namespace System.ComponentModel.Design
  18. {
  19.     using System;
  20.     using System.ComponentModel;
  21.     using System.Diagnostics;
  22.     using System.Globalization;
  23.     using System.Security.Permissions;
  24.    
  25.     /// <devdoc>
  26.     /// <para>
  27.     /// Represents a
  28.     /// numeric Command ID and globally unique
  29.     /// ID (GUID) menu identifier that together uniquely identify a command.
  30.     /// </para>
  31.     /// </devdoc>
  32.     [HostProtection(SharedState = true)]
  33.     [System.Runtime.InteropServices.ComVisible(true)]
  34.     [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name = "FullTrust")]
  35.     [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
  36.     public class CommandID
  37.     {
  38.         private readonly Guid menuGroup;
  39.         private readonly int commandID;
  40.        
  41.         /// <devdoc>
  42.         /// <para>
  43.         /// Initializes a new instance of the <see cref='System.ComponentModel.Design.CommandID'/>
  44.         /// class. Creates a new command
  45.         /// ID.
  46.         /// </para>
  47.         /// </devdoc>
  48.         public CommandID(Guid menuGroup, int commandID)
  49.         {
  50.             this.menuGroup = menuGroup;
  51.             this.commandID = commandID;
  52.         }
  53.        
  54.         /// <devdoc>
  55.         /// <para>
  56.         /// Gets or sets the numeric command ID.
  57.         /// </para>
  58.         /// </devdoc>
  59.         public virtual int ID {
  60.             get { return commandID; }
  61.         }
  62.        
  63.         /// <devdoc>
  64.         /// <para>
  65.         /// Overrides Object's Equals method.
  66.         /// </para>
  67.         /// </devdoc>
  68.         public override bool Equals(object obj)
  69.         {
  70.             if (!(obj is CommandID)) {
  71.                 return false;
  72.             }
  73.             CommandID cid = (CommandID)obj;
  74.             return cid.menuGroup.Equals(menuGroup) && cid.commandID == commandID;
  75.         }
  76.        
  77.         /// <devdoc>
  78.         /// <para>[To be supplied.]</para>
  79.         /// </devdoc>
  80.         public override int GetHashCode()
  81.         {
  82.             return menuGroup.GetHashCode() << 2 | commandID;
  83.         }
  84.        
  85.         /// <devdoc>
  86.         /// <para>
  87.         /// Gets or sets the globally
  88.         /// unique ID
  89.         /// (GUID) of the menu group that the menu command this CommandID
  90.         /// represents belongs to.
  91.         /// </para>
  92.         /// </devdoc>
  93.         public virtual Guid Guid {
  94.             get { return menuGroup; }
  95.         }
  96.        
  97.         /// <devdoc>
  98.         /// <para>
  99.         /// Overrides Object's ToString method.
  100.         /// </para>
  101.         /// </devdoc>
  102.         public override string ToString()
  103.         {
  104.             return menuGroup.ToString() + " : " + commandID.ToString(CultureInfo.CurrentCulture);
  105.         }
  106.     }
  107.    
  108. }

Developer Fusion