本文整理汇总了C#中ParseOptions类的典型用法代码示例。如果您正苦于以下问题:C# ParseOptions类的具体用法?C# ParseOptions怎么用?C# ParseOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseOptions类属于命名空间,在下文中一共展示了ParseOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBraceHighlightingAsync
protected async Task TestBraceHighlightingAsync(string markup, ParseOptions options = null)
{
using (var workspace = await CreateWorkspaceAsync(markup, options))
{
WpfTestCase.RequireWpfFact($"{nameof(AbstractBraceHighlightingTests)}.{nameof(TestBraceHighlightingAsync)} creates asynchronous taggers");
var provider = new BraceHighlightingViewTaggerProvider(
workspace.GetService<IBraceMatchingService>(),
workspace.GetService<IForegroundNotificationService>(),
AggregateAsynchronousOperationListener.EmptyListeners);
var testDocument = workspace.Documents.First();
var buffer = testDocument.TextBuffer;
var document = buffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault();
var context = new TaggerContext<BraceHighlightTag>(
document, buffer.CurrentSnapshot,
new SnapshotPoint(buffer.CurrentSnapshot, testDocument.CursorPosition.Value));
await provider.ProduceTagsAsync_ForTestingPurposesOnly(context);
var expectedHighlights = testDocument.SelectedSpans.Select(ts => ts.ToSpan()).OrderBy(s => s.Start).ToList();
var actualHighlights = context.tagSpans.Select(ts => ts.Span.Span).OrderBy(s => s.Start).ToList();
Assert.Equal(expectedHighlights, actualHighlights);
}
}
示例2: Test
private void Test(
string markup,
ParseOptions options,
bool optionIsEnabled = true)
{
using (var workspace = CreateWorkspaceFromFile(markup, options))
{
var testDocument = workspace.Documents.Single();
var expectedHighlightSpans = testDocument.SelectedSpans ?? new List<TextSpan>();
expectedHighlightSpans = Sort(expectedHighlightSpans);
var cursorSpan = testDocument.AnnotatedSpans["Cursor"].Single();
var textSnapshot = testDocument.TextBuffer.CurrentSnapshot;
var document = workspace.CurrentSolution.GetDocument(testDocument.Id);
// If the position being tested is immediately following the keyword,
// we should get the token before this position to find the appropriate
// ancestor node.
var highlighter = CreateHighlighter();
var root = document.GetSyntaxRootAsync().Result;
for (int i = 0; i <= cursorSpan.Length; i++)
{
var position = cursorSpan.Start + i;
var highlightSpans = highlighter.GetHighlights(root, position, CancellationToken.None).ToList();
highlightSpans = Sort(highlightSpans);
CheckSpans(expectedHighlightSpans, highlightSpans);
}
}
}
示例3: CompileAndVerify
internal CompilationVerifier CompileAndVerify(
string source,
IEnumerable<MetadataReference> additionalRefs = null,
IEnumerable<ModuleData> dependencies = null,
Action<IModuleSymbol> sourceSymbolValidator = null,
Action<PEAssembly> assemblyValidator = null,
Action<IModuleSymbol> symbolValidator = null,
SignatureDescription[] expectedSignatures = null,
string expectedOutput = null,
CompilationOptions options = null,
ParseOptions parseOptions = null,
bool verify = true)
{
return CompileAndVerify(
sources: new string[] { source },
additionalRefs: additionalRefs,
dependencies: dependencies,
sourceSymbolValidator: sourceSymbolValidator,
assemblyValidator: assemblyValidator,
symbolValidator: symbolValidator,
expectedSignatures: expectedSignatures,
expectedOutput: expectedOutput,
options: options,
parseOptions: parseOptions,
verify: verify);
}
示例4: TryParse
/// <summary>
/// Tries to parse the dataFields using the delimiter and fields. If true,
/// result will hold an IStringConverter that can convert all valid input
/// in the form of dataFields, only extracting fields.
/// </summary>
/// <param name="dataFields">Input string</param>
/// <param name="delimiter">Seperator</param>
/// <param name="fields">Required (conversion) fields</param>
/// <param name="result">Converter</param>
/// <param name="options">Parseoptions</param>
/// <returns>Parse is possible</returns>
public static Boolean TryParse(String dataFields, Char delimiter, String[] fields, out IStringConverter result,
ParseOptions options = ParseOptions.CleanupQuotes)
{
result = new DelimiterConverter(delimiter);
var splittedDataFields = new Queue<String>(dataFields.Split(delimiter));
var fieldsQueue = new Queue<String>(fields);
while (fieldsQueue.Count > 0 && splittedDataFields.Count > 0)
{
var field = fieldsQueue.Peek();
var data = splittedDataFields.Dequeue().Trim();
if (options.HasFlag(ParseOptions.GlueStrings))
while (data.StartsWith("\"") && !data.EndsWith("\"") && splittedDataFields.Count > 0)
data = data + "," + splittedDataFields.Dequeue().Trim();
if (options.HasFlag(ParseOptions.CleanupQuotes))
data = data.Replace("\"", "").Trim();
(result as DelimiterConverter).PushMask(field == data);
if (field == data)
fieldsQueue.Dequeue();
}
return fieldsQueue.Count == 0;
}
示例5: GenerateConstructorDeclaration
internal static ConstructorDeclarationSyntax GenerateConstructorDeclaration(
IMethodSymbol constructor, CodeGenerationDestination destination,
Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions)
{
options = options ?? CodeGenerationOptions.Default;
var reusableSyntax = GetReuseableSyntaxNodeForSymbol<ConstructorDeclarationSyntax>(constructor, options);
if (reusableSyntax != null)
{
return reusableSyntax;
}
bool hasNoBody = !options.GenerateMethodBodies;
var declaration = SyntaxFactory.ConstructorDeclaration(
attributeLists: AttributeGenerator.GenerateAttributeLists(constructor.GetAttributes(), options),
modifiers: GenerateModifiers(constructor, options),
identifier: CodeGenerationConstructorInfo.GetTypeName(constructor).ToIdentifierToken(),
parameterList: ParameterGenerator.GenerateParameterList(constructor.Parameters, isExplicit: false, options: options),
initializer: GenerateConstructorInitializer(constructor),
body: hasNoBody ? null : GenerateBlock(constructor),
semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : default(SyntaxToken));
declaration = UseExpressionBodyIfDesired(workspace, declaration, parseOptions);
return AddCleanupAnnotationsTo(
ConditionallyAddDocumentationCommentTo(declaration, constructor, options));
}
示例6: GenerateConversionDeclarationWorker
private static ConversionOperatorDeclarationSyntax GenerateConversionDeclarationWorker(
IMethodSymbol method,
CodeGenerationDestination destination,
Workspace workspace,
CodeGenerationOptions options,
ParseOptions parseOptions)
{
var hasNoBody = !options.GenerateMethodBodies || method.IsExtern;
var reusableSyntax = GetReuseableSyntaxNodeForSymbol<ConversionOperatorDeclarationSyntax>(method, options);
if (reusableSyntax != null)
{
return reusableSyntax;
}
var operatorToken = SyntaxFactory.Token(SyntaxFacts.GetOperatorKind(method.MetadataName));
var keyword = method.MetadataName == WellKnownMemberNames.ImplicitConversionName
? SyntaxFactory.Token(SyntaxKind.ImplicitKeyword)
: SyntaxFactory.Token(SyntaxKind.ExplicitKeyword);
var declaration = SyntaxFactory.ConversionOperatorDeclaration(
attributeLists: AttributeGenerator.GenerateAttributeLists(method.GetAttributes(), options),
modifiers: GenerateModifiers(method),
implicitOrExplicitKeyword: keyword,
operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword),
type: method.ReturnType.GenerateTypeSyntax(),
parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, isExplicit: false, options: options),
body: hasNoBody ? null : StatementGenerator.GenerateBlock(method),
semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken());
declaration = UseExpressionBodyIfDesired(workspace, declaration, parseOptions);
return declaration;
}
示例7: GenerateMethodDeclarationWorker
private static MethodDeclarationSyntax GenerateMethodDeclarationWorker(
IMethodSymbol method, CodeGenerationDestination destination,
Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions)
{
var hasNoBody = !options.GenerateMethodBodies ||
destination == CodeGenerationDestination.InterfaceType ||
method.IsAbstract;
var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(method.ExplicitInterfaceImplementations);
var returnType = method.ReturnsByRef
? method.ReturnType.GenerateRefTypeSyntax()
: method.ReturnType.GenerateTypeSyntax();
var methodDeclaration = SyntaxFactory.MethodDeclaration(
attributeLists: GenerateAttributes(method, options, explicitInterfaceSpecifier != null),
modifiers: GenerateModifiers(method, destination, options),
returnType: returnType,
explicitInterfaceSpecifier: explicitInterfaceSpecifier,
identifier: method.Name.ToIdentifierToken(),
typeParameterList: GenerateTypeParameterList(method, options),
parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, explicitInterfaceSpecifier != null, options),
constraintClauses: GenerateConstraintClauses(method),
body: hasNoBody ? null : StatementGenerator.GenerateBlock(method),
expressionBody: default(ArrowExpressionClauseSyntax),
semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken());
methodDeclaration = UseExpressionBodyIfDesired(workspace, methodDeclaration, parseOptions);
return AddCleanupAnnotationsTo(methodDeclaration);
}
示例8: WriteTo
public override void WriteTo(ParseOptions options, ObjectWriter writer, CancellationToken cancellationToken)
{
WriteParseOptionsTo(options, writer, cancellationToken);
var csharpOptions = (CSharpParseOptions)options;
writer.WriteInt32((int)csharpOptions.LanguageVersion);
writer.WriteValue(options.PreprocessorSymbolNames.ToArray());
}
示例9: CreateWorkspaceFromFileAsync
protected override async Task<TestWorkspace> CreateWorkspaceFromFileAsync(string definition, ParseOptions parseOptions, CompilationOptions compilationOptions)
{
var workspace = await base.CreateWorkspaceFromFileAsync(definition, parseOptions, compilationOptions);
workspace.Options = workspace.Options
.WithChangedOption(AddImportOptions.SuggestForTypesInNuGetPackages, LanguageNames.CSharp, true)
.WithChangedOption(AddImportOptions.SuggestForTypesInReferenceAssemblies, LanguageNames.CSharp, true);
return workspace;
}
示例10: CreateWorkspaceFromFilesAsync
/// <param name="files">Can pass in multiple file contents with individual source kind: files will be named test1.vb, test2.vbx, etc.</param>
public static Task<TestWorkspace> CreateWorkspaceFromFilesAsync(
string[] files,
ParseOptions[] parseOptions = null,
CompilationOptions compilationOptions = null,
ExportProvider exportProvider = null)
{
return TestWorkspaceFactory.CreateWorkspaceFromFilesAsync(LanguageNames.VisualBasic, compilationOptions, parseOptions, files, exportProvider);
}
示例11: Parser
/// <summary>
/// Initializes a new instance of the <see cref="Parser"/> class.
/// Returns the parser object that is used to store state throughout the
/// process of parsing.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="options">The options.</param>
protected Parser(Source source, ParseOptions options)
{
Source = source;
Options = options ?? new ParseOptions();
_lexToken = new Lexer(source);
PrevEnd = 0;
Token = _lexToken.NextToken();
}
示例12: CreateWorkspaceFromFileAsync
/// <summary>
/// Creates a single buffer in a workspace.
/// </summary>
/// <param name="content">Lines of text, the buffer contents</param>
internal static Task<TestWorkspace> CreateWorkspaceFromFileAsync(
string language,
CompilationOptions compilationOptions,
ParseOptions parseOptions,
string content)
{
return CreateWorkspaceFromFilesAsync(language, compilationOptions, parseOptions, new[] { content });
}
示例13: CreateAsync
public static async Task<ChangeSignatureTestState> CreateAsync(string markup, string languageName, ParseOptions parseOptions = null)
{
var workspace = languageName == LanguageNames.CSharp
? await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(markup, exportProvider: s_exportProvider, parseOptions: (CSharpParseOptions)parseOptions)
: await VisualBasicWorkspaceFactory.CreateWorkspaceFromFileAsync(markup, exportProvider: s_exportProvider, parseOptions: parseOptions, compilationOptions: new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
return new ChangeSignatureTestState(workspace);
}
示例14: TestWithAccessorCodeStyleOptionsOnAsync
internal async Task TestWithAccessorCodeStyleOptionsOnAsync(
string initialMarkup, string expectedMarkup,
int index = 0, bool compareTokens = true,
ParseOptions parseOptions = null,
bool withScriptOption = false)
{
await TestAsync(initialMarkup, expectedMarkup, parseOptions, null,
index, compareTokens, options: AccessorOptionsOn, withScriptOption: withScriptOption);
}
示例15: CreateWorkspaceFromFileAsync
public static Task<TestWorkspace> CreateWorkspaceFromFileAsync(
string file,
ParseOptions parseOptions = null,
CompilationOptions compilationOptions = null,
ExportProvider exportProvider = null,
string[] metadataReferences = null)
{
return CreateWorkspaceFromFilesAsync(new[] { file }, parseOptions, compilationOptions, exportProvider, metadataReferences);
}