本文整理汇总了C#中Compilation.GetEntryPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Compilation.GetEntryPoint方法的具体用法?C# Compilation.GetEntryPoint怎么用?C# Compilation.GetEntryPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compilation
的用法示例。
在下文中一共展示了Compilation.GetEntryPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProviderContainingEntryPointAsync
internal static async Task<Tuple<CodeProvider, IMethodSymbol>> GetProviderContainingEntryPointAsync(Compilation compilation, CancellationToken cancellationToken = default(CancellationToken))
{
var mainSymbol = compilation.GetEntryPoint(cancellationToken);
if (mainSymbol == null)
{
return null;
}
else
{
try
{
foreach (var tree in compilation.SyntaxTrees)
{
var finder = new MethodFinder(mainSymbol, compilation.GetSemanticModel(tree));
var root = await tree.GetRootAsync(cancellationToken);
finder.Visit(root);
if (finder.Result != null)
{
return new Tuple<CodeProvider, IMethodSymbol>(new CodeProvider(tree, compilation), mainSymbol);
}
}
}
catch (OperationCanceledException)
{
Console.Error.WriteLine("Cancelling...");
}
return null;
}
}
示例2: GetOutputFileName
/// <summary>
/// Given a compilation and a destination directory, determine three names:
/// 1) The name with which the assembly should be output.
/// 2) The path of the assembly/module file.
/// 3) The path of the pdb file.
///
/// When csc produces an executable, but the name of the resulting assembly
/// is not specified using the "/out" switch, the name is taken from the name
/// of the file (note: file, not class) containing the assembly entrypoint
/// (as determined by binding and the "/main" switch).
///
/// For example, if the command is "csc /target:exe a.cs b.cs" and b.cs contains the
/// entrypoint, then csc will produce "b.exe" and "b.pdb" in the output directory,
/// with assembly name "b" and module name "b.exe" embedded in the file.
/// </summary>
protected override string GetOutputFileName(Compilation compilation, CancellationToken cancellationToken)
{
if (Arguments.OutputFileName == null)
{
Debug.Assert(Arguments.CompilationOptions.OutputKind.IsApplication());
ISymbol entryPoint = (ISymbol)compilation.ScriptClass ?? compilation.GetEntryPoint(cancellationToken);
if (entryPoint != null)
{
string entryPointFileName = PathUtilities.GetFileName(entryPoint.Locations.First().SourceTree.FilePath);
return Path.ChangeExtension(entryPointFileName, ".exe");
}
else
{
// no entrypoint found - an error will be reported and the compilation won't be emitted
return "error";
}
}
else
{
return base.GetOutputFileName(compilation, cancellationToken);
}
}
示例3: GetProviderContainingEntryPoint
internal static CodeProvider GetProviderContainingEntryPoint(Compilation compilation, out IMethodSymbol mainSymbol)
{
mainSymbol = compilation.GetEntryPoint(new System.Threading.CancellationToken());
foreach (var tree in compilation.SyntaxTrees)
{
var finder = new MethodFinder(mainSymbol, compilation.GetSemanticModel(tree));
finder.Visit(tree.GetRoot());
if (finder.Result != null)
{
return new CodeProvider(tree, compilation);
}
}
return null;
}