private string GetStringFromCommandID(CommandID commandID) { if (commandID == null) { throw new ArgumentNullException("commandID"); } //v-oscca: //The services resourceManager and dte will be null during installation phase, this is becuase the component is not sited. //This is by design. IVsResourceManager resourceManager = (IVsResourceManager)GetService(typeof(SVsResourceManager)); if (resourceManager != null) { int localeId = CultureInfo.CurrentCulture.LCID; DTE dte = (DTE)GetService(typeof(DTE)); if (dte != null) { localeId = dte.LocaleID; } string valueAsString = null; Guid guid = commandID.Guid; resourceManager.LoadResourceString(ref guid, localeId, "#" + commandID.ID, out valueAsString); return(valueAsString); } return(null); }
public static string GetResourceString(string resourceName) { string resourceValue; IVsResourceManager resourceManager = (IVsResourceManager)GetGlobalService(typeof(SVsResourceManager)); Guid packageGuid = typeof(VSPackage).GUID; int hr = resourceManager.LoadResourceString(ref packageGuid, -1, resourceName, out resourceValue); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); return(resourceValue); }
/// <summary> /// This method loads a localized string based on the specified resource. /// </summary> /// <param name="resourceName">Resource to load</param> /// <returns>String loaded for the specified resource</returns> public string GetResourceString(string resourceName) { string resourceValue; IVsResourceManager resourceManager = (IVsResourceManager)GetService(typeof(SVsResourceManager)); if (resourceManager == null) { throw new InvalidOperationException("Could not get SVsResourceManager service. Make sure the package is Sited before calling this method"); } Guid packageGuid = this.GetType().GUID; int hr = resourceManager.LoadResourceString(ref packageGuid, -1, resourceName, out resourceValue); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); return(resourceValue); }
/// <summary> /// This method loads a localized string based on the specified resource. /// </summary> /// <param name="resourceName">Resource to load</param> /// <returns>String loaded for the specified resource</returns> internal string GetResourceString(string resourceName) { ThreadHelper.ThrowIfNotOnUIThread(); string resourceValue; IVsResourceManager resourceManager = (IVsResourceManager)GetService(typeof(SVsResourceManager)); if (resourceManager == null) { throw new InvalidOperationException("Could not get SVsResourceManager service. Make sure the package is Sited before calling this method"); } Guid packageGuid = _thisPackage.GetType().GUID; int hr = resourceManager.LoadResourceString(ref packageGuid, -1, resourceName, out resourceValue); ErrorHandler.ThrowOnFailure(hr); return(resourceValue); }