private void FindOptionService()
{
const string optionServiceTypeName = "Microsoft.CodeAnalysis.Options.IOptionService";
const string CodeAnalysisWorkspacesAssemblyName = "Microsoft.CodeAnalysis.Workspaces";
Type optionServiceType = typeof(PerLanguageOption<int>).Assembly.GetType(optionServiceTypeName, false);
if (optionServiceType == null)
{
VsShellUtils.WriteToSonarLintOutputPane(this.serviceProvider, Strings.MissingResourceAtLocation,
optionServiceTypeName, CodeAnalysisWorkspacesAssemblyName);
Debug.Fail($"{optionServiceTypeName} could not be found in {CodeAnalysisWorkspacesAssemblyName}");
return;
}
this.optionService = this.workspace.Services.GetType()
?.GetMethod("GetService")
?.MakeGenericMethod(optionServiceType)
?.Invoke(workspace.Services, null);
Debug.Assert(this.optionService != null, "Option service is null");
this.optionServiceSetOptionsMethod = optionServiceType?.GetMethod("SetOptions");
this.optionServiceGetOptionsMethod = optionServiceType?.GetMethod("GetOptions");
Debug.Assert(this.optionServiceSetOptionsMethod != null, "IOptionService.SetOptions method is not found");
Debug.Assert(this.optionServiceGetOptionsMethod != null, "IOptionService.GetOptions method is not found");
}