提交 49cc8841 编写于 作者: H Heejae Chang

use new language property of compilation/parseoption to find out which type it is

上级 22fc0144
......@@ -17,11 +17,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Execution
[ExportLanguageService(typeof(IOptionsSerializationService), LanguageNames.CSharp), Shared]
internal class CSharpOptionsSerializationService : AbstractOptionsSerializationService
{
public override bool CanSerialize(object value)
{
return value is CSharpCompilationOptions || value is CSharpParseOptions;
}
public override void WriteTo(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken)
{
WriteCompilationOptionsTo(options, writer, cancellationToken);
......
......@@ -14,8 +14,6 @@ namespace Microsoft.CodeAnalysis.Execution
{
internal abstract class AbstractOptionsSerializationService : IOptionsSerializationService
{
public abstract bool CanSerialize(object value);
public abstract void WriteTo(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken);
public abstract void WriteTo(ParseOptions options, ObjectWriter writer, CancellationToken cancellationToken);
public abstract void WriteTo(OptionSet options, ObjectWriter writer, CancellationToken cancellationToken);
......
......@@ -12,8 +12,6 @@ namespace Microsoft.CodeAnalysis.Execution
/// </summary>
internal interface IOptionsSerializationService : ILanguageService
{
bool CanSerialize(object value);
void WriteTo(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken);
void WriteTo(ParseOptions options, ObjectWriter writer, CancellationToken cancellationToken);
void WriteTo(OptionSet options, ObjectWriter writer, CancellationToken cancellationToken);
......
......@@ -190,49 +190,6 @@ public T Deserialize<T>(string kind, ObjectReader reader, CancellationToken canc
}
}
private string GetLanguageName(object value)
{
// for given object, we need to figure out which language the object belong to.
// we can't blindly get language service since that will bring in language specific dlls.
foreach (var languageName in _workspaceServices.SupportedLanguages)
{
IOptionsSerializationService service;
if (_lazyLanguageSerializationService.TryGetValue(languageName, out service))
{
if (service.CanSerialize(value))
{
return languageName;
}
continue;
}
// this should be only reached once per language value actually belong to
var mefWorkspaceServices = _workspaceServices as MefWorkspaceServices;
if (mefWorkspaceServices != null)
{
MefLanguageServices languageServices;
if (!mefWorkspaceServices.TryGetLanguageServices(languageName, out languageServices))
{
// this is a bit fragile since it depends on implementation detail but there is no other way
// to figure out which language a type belong to without loading other languages
//
// if a language's language services is not created yet, then it means that language is not loaded
continue;
}
}
service = GetOptionsSerializationService(languageName);
if (service.CanSerialize(value))
{
return languageName;
}
}
// shouldn't reach here
throw ExceptionUtilities.UnexpectedValue(value);
}
private IOptionsSerializationService GetOptionsSerializationService(string languageName)
{
return _lazyLanguageSerializationService.GetOrAdd(languageName, n => _workspaceServices.GetLanguageServices(n).GetService<IOptionsSerializationService>());
......
......@@ -159,9 +159,9 @@ public void SerializeCompilationOptions(CompilationOptions options, ObjectWriter
{
cancellationToken.ThrowIfCancellationRequested();
// TODO: once compiler team adds ability to serialize compilation options to ObjectWriter directly, we won't need this.
var language = GetLanguageName(options);
var language = options.Language;
// TODO: once compiler team adds ability to serialize compilation options to ObjectWriter directly, we won't need this.
writer.WriteString(language);
var service = GetOptionsSerializationService(language);
......@@ -182,7 +182,7 @@ public void SerializeParseOptions(ParseOptions options, ObjectWriter writer, Can
{
cancellationToken.ThrowIfCancellationRequested();
var language = GetLanguageName(options);
var language = options.Language;
// TODO: once compiler team adds ability to serialize parse options to ObjectWriter directly, we won't need this.
writer.WriteString(language);
......
......@@ -12,10 +12,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Execution
Friend Class VisualBasicOptionsSerializationService
Inherits AbstractOptionsSerializationService
Public Overrides Function CanSerialize(value As Object) As Boolean
Return (TypeOf value Is VisualBasicCompilationOptions) OrElse (TypeOf value Is VisualBasicParseOptions)
End Function
Public Overrides Sub WriteTo(options As CompilationOptions, writer As ObjectWriter, cancellationToken As CancellationToken)
WriteCompilationOptionsTo(options, writer, cancellationToken)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册