本文整理汇总了C#中CSharpCompilation.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation.Emit方法的具体用法?C# CSharpCompilation.Emit怎么用?C# CSharpCompilation.Emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpCompilation
的用法示例。
在下文中一共展示了CSharpCompilation.Emit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyEmitDiagnostics
// In VB use AssertTheseErrors format for expected diagnostics!
private static void VerifyEmitDiagnostics(
CSharpCompilation compilation,
bool metadataOnlyShouldSucceed,
DiagnosticDescription[] expectedFullBuildDiagnostics,
DiagnosticDescription[] expectedMetadataOnlyDiagnostics = null)
{
using (var executableStream = new MemoryStream())
{
var result = compilation.Emit(executableStream);
Assert.False(result.Success);
result.Diagnostics.Verify(expectedFullBuildDiagnostics);
}
using (var executableStream = new MemoryStream())
{
var result = compilation.Emit(executableStream, options: new EmitOptions(metadataOnly: true));
if (metadataOnlyShouldSucceed)
{
Assert.True(result.Success);
result.Diagnostics.Verify();
}
else
{
Assert.False(result.Success);
result.Diagnostics.Verify(expectedMetadataOnlyDiagnostics ?? expectedFullBuildDiagnostics);
}
}
}
示例2: VerifyAssemblyTable
internal void VerifyAssemblyTable(
CSharpCompilation compilation,
Action<AssemblyDefinition> verifier,
string strData = null,
byte[] blobData = null,
Guid guidData = default(Guid),
string uddData = null)
{
var stream = new MemoryStream();
Assert.True(compilation.Emit(stream).Success);
stream.Position = 0;
using (var metadata = ModuleMetadata.CreateFromImageStream(stream))
{
var peReader = metadata.MetadataReader;
AssemblyDefinition row = peReader.GetAssemblyDefinition();
if (verifier != null)
verifier(row);
// Locale
// temp
if (strData != null)
{
Assert.Equal(strData, peReader.GetString(row.Culture));
}
// PublicKey
//Assert.Equal((uint)0, row.PublicKey);
}
}