提交 c2fb6fce 编写于 作者: C CyrusNajmabadi

Use reflection to call into the right helper.

上级 f445e789
......@@ -20,11 +20,14 @@ internal interface IVsExperimentationService
[DispId(1610678272)]
Array AllEnabledCachedFlights { get; }
[return: ComAliasName("EnvDTE.ULONG_PTR")]
uint AdviseFlightEvents(IVsFlightEvents flightSink);
void Start();
bool IsCachedFlightEnabled([ComAliasName("OLE.LPCOLESTR")] string flightName);
IVsTask IsFlightEnabledAsync([ComAliasName("OLE.LPCOLESTR")] string flightName);
void Start();
[return: ComAliasName("EnvDTE.ULONG_PTR")]
uint AdviseFlightEvents(IVsFlightEvents flightSink);
void UnadviseFlightEvents([ComAliasName("EnvDTE.ULONG_PTR")] uint cookie);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using System.Reflection;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.Internal.VisualStudio.Shell.Interop;
......@@ -11,7 +12,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Experimentation
[ExportWorkspaceService(typeof(IExperimentationService), ServiceLayer.Host), Shared]
internal class VisualStudioExperimentationService : IExperimentationService
{
private readonly IVsExperimentationService _experimentationServiceOpt;
private readonly object _experimentationServiceOpt;
private readonly MethodInfo _isCachedFlightEnabledInfo;
[ImportingConstructor]
public VisualStudioExperimentationService(
......@@ -19,7 +21,12 @@ internal class VisualStudioExperimentationService : IExperimentationService
{
try
{
_experimentationServiceOpt = (IVsExperimentationService)serviceProvider.GetService(typeof(SVsServiceProvider));
_experimentationServiceOpt = serviceProvider.GetService(typeof(SVsExperimentationService));
if (_experimentationServiceOpt != null)
{
_isCachedFlightEnabledInfo = _experimentationServiceOpt.GetType().GetMethod(
"IsCachedFlightEnabled", BindingFlags.Public | BindingFlags.Instance);
}
}
catch
{
......@@ -27,6 +34,20 @@ internal class VisualStudioExperimentationService : IExperimentationService
}
public bool IsExperimentEnabled(string experimentName)
=> _experimentationServiceOpt?.IsCachedFlightEnabled(experimentName) ?? false;
{
if (_isCachedFlightEnabledInfo != null)
{
try
{
return (bool)_isCachedFlightEnabledInfo.Invoke(_experimentationServiceOpt, new object[] { experimentName });
}
catch
{
}
}
return false;
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册