Created
January 21, 2016 16:33
-
-
Save FransBouma/60ec21b909743973d5a2 to your computer and use it in GitHub Desktop.
How to get the theme ID inside a vs.net extension without using references to vsnet2012 dlls (so code can be added to 2010 vsix too)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var themeService = this.ActiveServiceProvider.GetService(new Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")); | |
if(themeService == null) | |
{ | |
// no theming, no problem! | |
return; | |
} | |
var currentThemeProperty = themeService.GetType().GetProperty("CurrentTheme"); | |
if(currentThemeProperty == null) | |
{ | |
// something's wrong. No theming for you | |
return; | |
} | |
var currentTheme = currentThemeProperty.GetValue(themeService, null); | |
if(currentTheme == null) | |
{ | |
// user has no theme. We can't help further | |
return; | |
} | |
var themeIdProperty = currentTheme.GetType().GetProperty("ThemeId"); | |
if(themeIdProperty == null) | |
{ | |
return; | |
} | |
var themeIdGuid = themeIdProperty.GetValue(currentTheme, null); | |
if(themeIdGuid == null) | |
{ | |
return; | |
} | |
// use id here. IDs of common themes: | |
//Blue: {a4d6a176-b948-4b29-8c66-53c97a1ed7d0} | |
//Dark: {1ded0138-47ce-435e-84ef-9ec1f439b749} | |
//Light: {de3dbbcd-f642-433c-8353-8f1df4370aba} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for documenting this stuff! Is
ActiveServiceProvider
your own wrapper to look up services viaGuid
? Not something I've seen else where, but looks handy! Struggling with VS being able to use anything in theMicrosoft.Internal.VisualStudio.Shell.Interop
namespace. Can see which DLL to get the type from but still complains missing reference (egIVsColorThemeService
),ActiveServiceProvider
+ reflection looks like a good way to get around the issue.