public void GetExtenderCATID_ReturnsCorrectCadId(ExtenderCATIDType input, string expected) { var provider = CreateInstance(); var result = provider.GetExtenderCATID(input, (IProjectTree)null); Assert.Equal(expected, result); }
// TODO remove suppression once CPS annotation corrected #pragma warning disable CS8613 // Nullability of reference types in return type doesn't match implicitly implemented member. public string?GetExtenderCATID(ExtenderCATIDType extenderCATIDType, IProjectTree?treeNode) #pragma warning restore CS8613 // Nullability of reference types in return type doesn't match implicitly implemented member. { // CPS's implementation of ExtenderCATIDType incorrectly treats the same "instances" as distinct items based // where they are accessed in CPS. It also incorrectly maps "HierarchyExtensionObject" and "HierarchyBrowseObject" // as only applying to the hierarchy, when they take ITEMIDs indicating the node they apply to. // // See https://docs.microsoft.com/en-us/visualstudio/extensibility/internals/extending-the-object-model-of-the-base-project. // // The latter issue we can do nothing about, however, to address the former, map these types to a truer form it makes // it easier on implementors and maintainers of this to understand the objects we're talking about. switch (extenderCATIDType) { case ExtenderCATIDType.HierarchyExtensionObject: // IVsHierarchy.GetProperty(VSITEMID.Root, VSHPROPID_ExtObjectCATID) case ExtenderCATIDType.AutomationProject: // DTE.Project return(GetExtenderCATID(ExtendeeObject.Project)); case ExtenderCATIDType.HierarchyBrowseObject: // IVsHierarchy.GetProperty(VSHPROPID_BrowseObjectCATID) case ExtenderCATIDType.ProjectBrowseObject: // EnvDTE.Project.Properties return(GetExtenderCATID(ExtendeeObject.ProjectBrowseObject)); case ExtenderCATIDType.ConfigurationBrowseObject: // IVsCfgProvider2.GetCfgProviderProperty(VSCFGPROPID_IntrinsicExtenderCATID)/DTE.Configuration return(GetExtenderCATID(ExtendeeObject.Configuration)); case ExtenderCATIDType.HierarchyConfigurationBrowseObject: // IVsHierarchy.GetProperty(VSHPROPID_CfgBrowseObjectCATID) case ExtenderCATIDType.ProjectConfigurationBrowseObject: // EnvDTE.Configuration.Properties return(GetExtenderCATID(ExtendeeObject.ConfigurationBrowseObject)); case ExtenderCATIDType.AutomationProjectItem: // EnvDTE.ProjectItem return(GetExtenderCATID(ExtendeeObject.ProjectItem)); case ExtenderCATIDType.AutomationReference: // VSLangProject.Reference case ExtenderCATIDType.ReferenceBrowseObject: // EnvDTE.ProjectItem.Properties (when reference) return(GetExtenderCATID(ExtendeeObject.ReferenceBrowseObject)); case ExtenderCATIDType.FileBrowseObject: // EnvDTE.ProjectItem.Properties (when file) return(GetExtenderCATID(ExtendeeObject.FileBrowseObject)); case ExtenderCATIDType.AutomationFolderProperties: // FolderProperties case ExtenderCATIDType.FolderBrowseObject: // EnvDTE.ProjectItem.Properties (when folder) return(GetExtenderCATID(ExtendeeObject.FolderBrowseObject)); default: case ExtenderCATIDType.Unknown: // EnvDTE.ProjectItem.Properties (when not file, folder, reference) BCLDebug.Assert(extenderCATIDType == ExtenderCATIDType.Unknown, $"Unrecognized CATID type {extenderCATIDType}"); return(null); } }
public string?GetExtenderCATID(ExtenderCATIDType extenderCATIDType, IProjectTree?treeNode) { // CPS's implementation of ExtenderCATIDType incorrectly treats the same "instances" as distinct items based // where they are accessed in CPS. It also incorrectly maps "HierarchyExtensionObject" and "HierarchyBrowseObject" // as only applying to the hierarchy, when they take ITEMIDs indicating the node they apply to. // // See https://docs.microsoft.com/en-us/visualstudio/extensibility/internals/extending-the-object-model-of-the-base-project. // // The latter issue we can do nothing about, however, to address the former, map these types to a truer form it makes // it easier on implementors and maintainers of this to understand the objects we're talking about. return(extenderCATIDType switch { ExtenderCATIDType.HierarchyExtensionObject or // IVsHierarchy.GetProperty(VSITEMID.Root, VSHPROPID_ExtObjectCATID) ExtenderCATIDType.AutomationProject => // DTE.Project GetExtenderCATID(ExtendeeObject.Project), ExtenderCATIDType.HierarchyBrowseObject or // IVsHierarchy.GetProperty(VSHPROPID_BrowseObjectCATID) ExtenderCATIDType.ProjectBrowseObject => // EnvDTE.Project.Properties GetExtenderCATID(ExtendeeObject.ProjectBrowseObject), ExtenderCATIDType.ConfigurationBrowseObject => // IVsCfgProvider2.GetCfgProviderProperty(VSCFGPROPID_IntrinsicExtenderCATID)/DTE.Configuration GetExtenderCATID(ExtendeeObject.Configuration), ExtenderCATIDType.HierarchyConfigurationBrowseObject or // IVsHierarchy.GetProperty(VSHPROPID_CfgBrowseObjectCATID) ExtenderCATIDType.ProjectConfigurationBrowseObject => // EnvDTE.Configuration.Properties GetExtenderCATID(ExtendeeObject.ConfigurationBrowseObject), ExtenderCATIDType.AutomationProjectItem => // EnvDTE.ProjectItem GetExtenderCATID(ExtendeeObject.ProjectItem), ExtenderCATIDType.AutomationReference or // VSLangProject.Reference ExtenderCATIDType.ReferenceBrowseObject => // EnvDTE.ProjectItem.Properties (when reference) GetExtenderCATID(ExtendeeObject.ReferenceBrowseObject), ExtenderCATIDType.FileBrowseObject => // EnvDTE.ProjectItem.Properties (when file) GetExtenderCATID(ExtendeeObject.FileBrowseObject), ExtenderCATIDType.AutomationFolderProperties or // FolderProperties ExtenderCATIDType.FolderBrowseObject => // EnvDTE.ProjectItem.Properties (when folder) GetExtenderCATID(ExtendeeObject.FolderBrowseObject), ExtenderCATIDType.Unknown or _ => // EnvDTE.ProjectItem.Properties (when not file, folder, reference) UnknownOrDefault() });