本文整理汇总了C#中HostLanguageServices.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# HostLanguageServices.GetService方法的具体用法?C# HostLanguageServices.GetService怎么用?C# HostLanguageServices.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HostLanguageServices
的用法示例。
在下文中一共展示了HostLanguageServices.GetService方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeModelState
public CodeModelState(
IServiceProvider serviceProvider,
HostLanguageServices languageServices,
VisualStudioWorkspace workspace)
{
Debug.Assert(serviceProvider != null);
Debug.Assert(languageServices != null);
Debug.Assert(workspace != null);
this.ServiceProvider = serviceProvider;
this.CodeModelService = languageServices.GetService<ICodeModelService>();
this.SyntaxFactsService = languageServices.GetService<ISyntaxFactsService>();
this.CodeGenerator = languageServices.GetService<ICodeGenerationService>();
this.Workspace = workspace;
}
示例2: CSharpSyntaxTriviaService
public CSharpSyntaxTriviaService(HostLanguageServices provider)
: base(provider.GetService<ISyntaxFactsService>(), (int)SyntaxKind.EndOfLineTrivia)
{
}
示例3: CreateDocument
private static TestHostDocument CreateDocument(
TestWorkspace workspace,
XElement workspaceElement,
XElement documentElement,
string language,
ExportProvider exportProvider,
HostLanguageServices languageServiceProvider,
Dictionary<string, ITextBuffer> filePathToTextBufferMap,
ref int documentId)
{
string markupCode;
string filePath;
var isLinkFileAttribute = documentElement.Attribute(IsLinkFileAttributeName);
bool isLinkFile = isLinkFileAttribute != null && ((bool?)isLinkFileAttribute).HasValue && ((bool?)isLinkFileAttribute).Value;
if (isLinkFile)
{
// This is a linked file. Use the filePath and markup from the referenced document.
var originalProjectName = documentElement.Attribute(LinkAssemblyNameAttributeName);
var originalDocumentPath = documentElement.Attribute(LinkFilePathAttributeName);
if (originalProjectName == null || originalDocumentPath == null)
{
throw new ArgumentException("Linked file specified without LinkAssemblyName or LinkFilePath.");
}
var originalProjectNameStr = originalProjectName.Value;
var originalDocumentPathStr = originalDocumentPath.Value;
var originalProject = workspaceElement.Elements(ProjectElementName).First(p =>
{
var assemblyName = p.Attribute(AssemblyNameAttributeName);
return assemblyName != null && assemblyName.Value == originalProjectNameStr;
});
if (originalProject == null)
{
throw new ArgumentException("Linked file's LinkAssemblyName '{0}' project not found.", originalProjectNameStr);
}
var originalDocument = originalProject.Elements(DocumentElementName).First(d =>
{
var documentPath = d.Attribute(FilePathAttributeName);
return documentPath != null && documentPath.Value == originalDocumentPathStr;
});
if (originalDocument == null)
{
throw new ArgumentException("Linked file's LinkFilePath '{0}' file not found.", originalDocumentPathStr);
}
markupCode = originalDocument.NormalizedValue();
filePath = GetFilePath(workspace, originalDocument, ref documentId);
}
else
{
markupCode = documentElement.NormalizedValue();
filePath = GetFilePath(workspace, documentElement, ref documentId);
}
var folders = GetFolders(documentElement);
var optionsElement = documentElement.Element(ParseOptionsElementName);
// TODO: Allow these to be specified.
var codeKind = SourceCodeKind.Regular;
if (optionsElement != null)
{
var attr = optionsElement.Attribute(KindAttributeName);
codeKind = attr == null
? SourceCodeKind.Regular
: (SourceCodeKind)Enum.Parse(typeof(SourceCodeKind), attr.Value);
}
var contentTypeLanguageService = languageServiceProvider.GetService<IContentTypeLanguageService>();
var contentType = contentTypeLanguageService.GetDefaultContentType();
string code;
int? cursorPosition;
IDictionary<string, IList<TextSpan>> spans;
MarkupTestFile.GetPositionAndSpans(markupCode, out code, out cursorPosition, out spans);
// For linked files, use the same ITextBuffer for all linked documents
ITextBuffer textBuffer;
if (!filePathToTextBufferMap.TryGetValue(filePath, out textBuffer))
{
textBuffer = EditorFactory.CreateBuffer(contentType.TypeName, exportProvider, code);
filePathToTextBufferMap.Add(filePath, textBuffer);
}
return new TestHostDocument(exportProvider, languageServiceProvider, textBuffer, filePath, cursorPosition, spans, codeKind, folders, isLinkFile);
}
示例4: GetParseOptionsWorker
private static ParseOptions GetParseOptionsWorker(XElement projectElement, string language, HostLanguageServices languageServices)
{
ParseOptions parseOptions;
var preprocessorSymbolsAttribute = projectElement.Attribute(PreprocessorSymbolsAttributeName);
if (preprocessorSymbolsAttribute != null)
{
parseOptions = GetPreProcessorParseOptions(language, preprocessorSymbolsAttribute);
}
else
{
parseOptions = languageServices.GetService<ISyntaxTreeFactoryService>().GetDefaultParseOptions();
}
var languageVersionAttribute = projectElement.Attribute(LanguageVersionAttributeName);
if (languageVersionAttribute != null)
{
parseOptions = GetParseOptionsWithLanguageVersion(language, parseOptions, languageVersionAttribute);
}
var documentationMode = GetDocumentationMode(projectElement);
if (documentationMode != null)
{
parseOptions = parseOptions.WithDocumentationMode(documentationMode.Value);
}
return parseOptions;
}
示例5: CSharpSymbolDisplayService
public CSharpSymbolDisplayService(HostLanguageServices provider)
: base(provider.GetService<IAnonymousTypeDisplayService>())
{
}
示例6: FullyParseTreeAsync
private static async Task<TreeAndVersion> FullyParseTreeAsync(
ValueSource<TextAndVersion> newTextSource,
string filePath,
ParseOptions options,
HostLanguageServices languageServices,
PreservationMode mode,
CancellationToken cancellationToken)
{
using (Logger.LogBlock(FeatureId.DocumentState, FunctionId.DocumentState_FullyParseSyntaxTree, cancellationToken))
{
var textAndVersion = await newTextSource.GetValueAsync(cancellationToken).ConfigureAwait(false);
var text = textAndVersion.Text;
var treeFactory = languageServices.GetService<ISyntaxTreeFactoryService>();
var tree = treeFactory.ParseSyntaxTree(filePath, options, text, cancellationToken);
if (mode == PreservationMode.PreserveValue)
{
var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
// get a recoverable tree that reparses from the source text if it gets used after being kicked out of memory
tree = treeFactory.CreateRecoverableTree(tree.FilePath, tree.Options, newTextSource, root, reparse: true);
}
Contract.ThrowIfNull(tree);
// text version for this document should be unique. use it as a starting point.
return TreeAndVersion.Create(tree, textAndVersion.Version);
}
}
示例7: CSharpMetadataAsSourceService
public CSharpMetadataAsSourceService(HostLanguageServices languageServices)
: base(languageServices.GetService<ICodeGenerationService>())
{
}
示例8: FullyParseTreeAsync
private static async Task<TreeAndVersion> FullyParseTreeAsync(
ValueSource<TextAndVersion> newTextSource,
ProjectId cacheKey,
string filePath,
ParseOptions options,
HostLanguageServices languageServices,
SolutionServices solutionServices,
PreservationMode mode,
CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.Workspace_Document_State_FullyParseSyntaxTree, cancellationToken))
{
var textAndVersion = await newTextSource.GetValueAsync(cancellationToken).ConfigureAwait(false);
var text = textAndVersion.Text;
var treeFactory = languageServices.GetService<ISyntaxTreeFactoryService>();
var tree = treeFactory.ParseSyntaxTree(filePath, options, text, cancellationToken);
if (mode == PreservationMode.PreserveValue && solutionServices.SupportsCachingRecoverableObjects)
{
var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
tree = treeFactory.CreateRecoverableTree(cacheKey, tree.FilePath, tree.Options, newTextSource, root);
}
Contract.ThrowIfNull(tree);
// text version for this document should be unique. use it as a starting point.
return TreeAndVersion.Create(tree, textAndVersion.Version);
}
}
示例9: CreateTreeAndVersion
private static TreeAndVersion CreateTreeAndVersion(
ValueSource<TextAndVersion> newTextSource,
ProjectId cacheKey, string filePath,
ParseOptions options, HostLanguageServices languageServices,
PreservationMode mode, TextAndVersion textAndVersion,
CancellationToken cancellationToken)
{
var text = textAndVersion.Text;
var treeFactory = languageServices.GetService<ISyntaxTreeFactoryService>();
var tree = treeFactory.ParseSyntaxTree(filePath, options, text, cancellationToken);
var root = tree.GetRoot(cancellationToken);
if (mode == PreservationMode.PreserveValue && treeFactory.CanCreateRecoverableTree(root))
{
tree = treeFactory.CreateRecoverableTree(cacheKey, tree.FilePath, tree.Options, newTextSource, text.Encoding, root);
}
Contract.ThrowIfNull(tree);
// text version for this document should be unique. use it as a starting point.
return TreeAndVersion.Create(tree, textAndVersion.Version);
}
示例10: CreateLanguageService
public ILanguageService CreateLanguageService(HostLanguageServices provider)
{
// This interface is implemented by the ICodeModelService as well, so just grab the other one and return it
return provider.GetService<ICodeModelService>();
}