本文整理汇总了C#中SyntaxTree.WhereNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTree.WhereNotNull方法的具体用法?C# SyntaxTree.WhereNotNull怎么用?C# SyntaxTree.WhereNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxTree
的用法示例。
在下文中一共展示了SyntaxTree.WhereNotNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCompilation
public override Compilation CreateCompilation(TextWriter consoleOutput, TouchedFileLogger touchedFilesLogger, ErrorLogger errorLogger)
{
var parseOptions = Arguments.ParseOptions;
var scriptParseOptions = parseOptions.WithKind(SourceCodeKind.Script);
bool hadErrors = false;
var sourceFiles = Arguments.SourceFiles;
var trees = new SyntaxTree[sourceFiles.Length];
var normalizedFilePaths = new String[sourceFiles.Length];
if (Arguments.CompilationOptions.ConcurrentBuild)
{
Parallel.For(0, sourceFiles.Length, UICultureUtilities.WithCurrentUICulture<int>(i =>
{
//NOTE: order of trees is important!!
trees[i] = ParseFile(consoleOutput, parseOptions, scriptParseOptions, ref hadErrors, sourceFiles[i], errorLogger, out normalizedFilePaths[i]);
}));
}
else
{
for (int i = 0; i < sourceFiles.Length; i++)
{
//NOTE: order of trees is important!!
trees[i] = ParseFile(consoleOutput, parseOptions, scriptParseOptions, ref hadErrors, sourceFiles[i], errorLogger, out normalizedFilePaths[i]);
}
}
// If errors had been reported in ParseFile, while trying to read files, then we should simply exit.
if (hadErrors)
{
return null;
}
var diagnostics = new List<DiagnosticInfo>();
var uniqueFilePaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < sourceFiles.Length; i++)
{
var normalizedFilePath = normalizedFilePaths[i];
Debug.Assert(normalizedFilePath != null);
Debug.Assert(PathUtilities.IsAbsolute(normalizedFilePath));
if (!uniqueFilePaths.Add(normalizedFilePath))
{
// warning CS2002: Source file '{0}' specified multiple times
diagnostics.Add(new DiagnosticInfo(MessageProvider, (int)ErrorCode.WRN_FileAlreadyIncluded,
Arguments.PrintFullPaths ? normalizedFilePath : _diagnosticFormatter.RelativizeNormalizedPath(normalizedFilePath)));
trees[i] = null;
}
}
if (Arguments.TouchedFilesPath != null)
{
foreach (var path in uniqueFilePaths)
{
touchedFilesLogger.AddRead(path);
}
}
var assemblyIdentityComparer = DesktopAssemblyIdentityComparer.Default;
var appConfigPath = this.Arguments.AppConfigPath;
if (appConfigPath != null)
{
try
{
using (var appConfigStream = PortableShim.FileStream.Create(appConfigPath, PortableShim.FileMode.Open, PortableShim.FileAccess.Read))
{
assemblyIdentityComparer = DesktopAssemblyIdentityComparer.LoadFromXml(appConfigStream);
}
if (touchedFilesLogger != null)
{
touchedFilesLogger.AddRead(appConfigPath);
}
}
catch (Exception ex)
{
diagnostics.Add(new DiagnosticInfo(MessageProvider, (int)ErrorCode.ERR_CantReadConfigFile, appConfigPath, ex.Message));
}
}
var xmlFileResolver = new LoggingXmlFileResolver(Arguments.BaseDirectory, touchedFilesLogger);
var sourceFileResolver = new LoggingSourceFileResolver(ImmutableArray<string>.Empty, Arguments.BaseDirectory, touchedFilesLogger);
MetadataReferenceResolver referenceDirectiveResolver;
var resolvedReferences = ResolveMetadataReferences(diagnostics, touchedFilesLogger, out referenceDirectiveResolver);
if (ReportErrors(diagnostics, consoleOutput, errorLogger))
{
return null;
}
var strongNameProvider = new LoggingStrongNameProvider(Arguments.KeyFileSearchPaths, touchedFilesLogger);
var compilation = CSharpCompilation.Create(
Arguments.CompilationName,
trees.WhereNotNull(),
resolvedReferences,
Arguments.CompilationOptions.
//.........这里部分代码省略.........
示例2: CreateCompilation
//.........这里部分代码省略.........
//NOTE: order of trees is important!!
trees[i] = ParseFile(consoleOutput, parseOptions, scriptParseOptions, ref hadErrors, file, out normalizedFilePaths[i]);
}
}
// If errors had been reported in ParseFile, while trying to read files, then we should simply exit.
if (hadErrors)
{
return null;
}
var diagnostics = new List<DiagnosticInfo>();
var uniqueFilePaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < sourceFiles.Length; i++)
{
var normalizedFilePath = normalizedFilePaths[i];
Debug.Assert(normalizedFilePath != null);
Debug.Assert(PathUtilities.IsAbsolute(normalizedFilePath));
if (!uniqueFilePaths.Add(normalizedFilePath))
{
// warning CS2002: Source file '{0}' specified multiple times
diagnostics.Add(new DiagnosticInfo(MessageProvider, (int)ErrorCode.WRN_FileAlreadyIncluded,
Arguments.PrintFullPaths ? normalizedFilePath : this.diagnosticFormatter.RelativizeNormalizedPath(normalizedFilePath)));
trees[i] = null;
}
}
if (Arguments.TouchedFilesPath != null)
{
foreach (var path in uniqueFilePaths)
{
touchedFilesLogger.AddRead(path);
}
}
var assemblyIdentityComparer = DesktopAssemblyIdentityComparer.Default;
var appConfigPath = this.Arguments.AppConfigPath;
if (appConfigPath != null)
{
try
{
using (var appConfigStream = new FileStream(appConfigPath, FileMode.Open, FileAccess.Read))
{
assemblyIdentityComparer = DesktopAssemblyIdentityComparer.LoadFromXml(appConfigStream);
}
if (touchedFilesLogger != null)
{
touchedFilesLogger.AddRead(appConfigPath);
}
}
catch (Exception ex)
{
diagnostics.Add(new DiagnosticInfo(MessageProvider, (int)ErrorCode.ERR_CantReadConfigFile, appConfigPath, ex.Message));
}
}
var metadataProvider = GetMetadataProvider();
var xmlFileResolver = new LoggingXmlFileResolver(Arguments.BaseDirectory, touchedFilesLogger);
var sourceFileResolver = new LoggingSourceFileResolver(ImmutableArray<string>.Empty, Arguments.BaseDirectory, touchedFilesLogger);
var externalReferenceResolver = GetExternalMetadataResolver(touchedFilesLogger);
MetadataReferenceResolver referenceDirectiveResolver;
var resolvedReferences = ResolveMetadataReferences(externalReferenceResolver, metadataProvider, diagnostics, assemblyIdentityComparer, touchedFilesLogger, out referenceDirectiveResolver);
if (PrintErrors(diagnostics, consoleOutput))
{
return null;
}
var strongNameProvider = new LoggingStrongNameProvider(Arguments.KeyFileSearchPaths, touchedFilesLogger);
var compilation = CSharpCompilation.Create(
Arguments.CompilationName,
trees.WhereNotNull(),
resolvedReferences,
Arguments.CompilationOptions.
WithMetadataReferenceResolver(referenceDirectiveResolver).
WithMetadataReferenceProvider(metadataProvider).
WithAssemblyIdentityComparer(assemblyIdentityComparer).
WithStrongNameProvider(strongNameProvider).
WithXmlReferenceResolver(xmlFileResolver).
WithSourceReferenceResolver(sourceFileResolver));
// Print the diagnostics produced during the parsing stage and exit if there were any errors.
if (PrintErrors(compilation.GetParseDiagnostics(), consoleOutput))
{
return null;
}
if (PrintErrors(compilation.GetDeclarationDiagnostics(), consoleOutput))
{
return null;
}
return compilation;
}