本文整理汇总了C#中EmitOptions类的典型用法代码示例。如果您正苦于以下问题:C# EmitOptions类的具体用法?C# EmitOptions怎么用?C# EmitOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmitOptions类属于命名空间,在下文中一共展示了EmitOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileAndVerify
internal CompilationVerifier CompileAndVerify(
string[] sources,
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,
EmitOptions emitOptions = null,
bool verify = true)
{
if (options == null)
{
options = CompilationOptionsReleaseDll.WithOutputKind((expectedOutput != null) ? OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary);
}
var compilation = GetCompilationForEmit(sources, additionalRefs, options, parseOptions);
return this.CompileAndVerify(
compilation,
null,
dependencies,
sourceSymbolValidator,
assemblyValidator,
symbolValidator,
expectedSignatures,
expectedOutput,
emitOptions,
verify);
}
示例2: EEAssemblyBuilder
public EEAssemblyBuilder(
SourceAssemblySymbol sourceAssembly,
EmitOptions emitOptions,
ImmutableArray<MethodSymbol> methods,
ModulePropertiesForSerialization serializationProperties,
ImmutableArray<NamedTypeSymbol> additionalTypes,
NamedTypeSymbol dynamicOperationContextType,
CompilationTestData testData) :
base(
sourceAssembly,
emitOptions,
outputKind: OutputKind.DynamicallyLinkedLibrary,
serializationProperties: serializationProperties,
manifestResources: SpecializedCollections.EmptyEnumerable<ResourceDescription>(),
additionalTypes: additionalTypes)
{
Methods = ImmutableHashSet.CreateRange(methods);
_dynamicOperationContextType = dynamicOperationContextType;
if (testData != null)
{
this.SetMethodTestData(testData.Methods);
testData.Module = this;
}
}
示例3: CompileAndVerify
private CompilationVerifier CompileAndVerify(string source, string expectedOutput, IEnumerable<MetadataReference> references = null, EmitOptions emitOptions = EmitOptions.All, CSharpCompilationOptions compOptions = null)
{
SynchronizationContext.SetSynchronizationContext(null);
var compilation = this.CreateCompilation(source, references: references, compOptions: compOptions);
return base.CompileAndVerify(compilation, expectedOutput: expectedOutput, emitOptions: emitOptions);
}
示例4: EmitToArray
internal static ImmutableArray<byte> EmitToArray(
this Compilation compilation,
EmitOptions options = null,
CompilationTestData testData = null,
DiagnosticDescription[] expectedWarnings = null)
{
var stream = new MemoryStream();
MemoryStream pdbStream =
(compilation.Options.OptimizationLevel == OptimizationLevel.Debug) && !CLRHelpers.IsRunningOnMono()
? new MemoryStream()
: null;
var emitResult = compilation.Emit(
peStream: stream,
pdbStream: pdbStream,
xmlDocumentationStream: null,
win32Resources: null,
manifestResources: null,
options: options,
testData: testData,
getHostDiagnostics: null,
cancellationToken: default(CancellationToken));
Assert.True(emitResult.Success, "Diagnostics:\r\n" + string.Join("\r\n", emitResult.Diagnostics.Select(d => d.ToString())));
if (expectedWarnings != null)
{
emitResult.Diagnostics.Verify(expectedWarnings);
}
return stream.ToImmutable();
}
示例5: PENetModuleBuilder
internal PENetModuleBuilder(
SourceModuleSymbol sourceModule,
EmitOptions emitOptions,
Cci.ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources)
: base(sourceModule, emitOptions, OutputKind.NetModule, serializationProperties, manifestResources)
{
}
示例6: PENetModuleBuilder
internal PENetModuleBuilder(
PhpCompilation compilation,
IModuleSymbol sourceModule,
EmitOptions emitOptions,
Microsoft.Cci.ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources)
: base(compilation, (Symbols.SourceModuleSymbol)sourceModule, serializationProperties, manifestResources, OutputKind.NetModule, emitOptions)
{
}
示例7: PEDeltaAssemblyBuilder
public PEDeltaAssemblyBuilder(
SourceAssemblySymbol sourceAssembly,
EmitOptions emitOptions,
OutputKind outputKind,
Cci.ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources,
EmitBaseline previousGeneration,
IEnumerable<SemanticEdit> edits,
Func<ISymbol, bool> isAddedSymbol)
: base(sourceAssembly, emitOptions, outputKind, serializationProperties, manifestResources, additionalTypes: ImmutableArray<NamedTypeSymbol>.Empty)
{
var initialBaseline = previousGeneration.InitialBaseline;
var context = new EmitContext(this, null, new DiagnosticBag());
// Hydrate symbols from initial metadata. Once we do so it is important to reuse these symbols across all generations,
// in order for the symbol matcher to be able to use reference equality once it maps symbols to initial metadata.
var metadataSymbols = GetOrCreateMetadataSymbols(initialBaseline, sourceAssembly.DeclaringCompilation);
var metadataDecoder = (MetadataDecoder)metadataSymbols.MetadataDecoder;
var metadataAssembly = (PEAssemblySymbol)metadataDecoder.ModuleSymbol.ContainingAssembly;
var matchToMetadata = new CSharpSymbolMatcher(metadataSymbols.AnonymousTypes, sourceAssembly, context, metadataAssembly);
CSharpSymbolMatcher matchToPrevious = null;
if (previousGeneration.Ordinal > 0)
{
var previousAssembly = ((CSharpCompilation)previousGeneration.Compilation).SourceAssembly;
var previousContext = new EmitContext((PEModuleBuilder)previousGeneration.PEModuleBuilder, null, new DiagnosticBag());
matchToPrevious = new CSharpSymbolMatcher(
previousGeneration.AnonymousTypeMap,
sourceAssembly: sourceAssembly,
sourceContext: context,
otherAssembly: previousAssembly,
otherContext: previousContext,
otherSynthesizedMembersOpt: previousGeneration.SynthesizedMembers);
}
_previousDefinitions = new CSharpDefinitionMap(previousGeneration.OriginalMetadata.Module, edits, metadataDecoder, matchToMetadata, matchToPrevious);
_previousGeneration = previousGeneration;
_changes = new SymbolChanges(_previousDefinitions, edits, isAddedSymbol);
// Workaround for https://github.com/dotnet/roslyn/issues/3192.
// When compiling state machine we stash types of awaiters and state-machine hoisted variables,
// so that next generation can look variables up and reuse their slots if possible.
//
// When we are about to allocate a slot for a lifted variable while compiling the next generation
// we map its type to the previous generation and then check the slot types that we stashed earlier.
// If the variable type matches we reuse it. In order to compare the previous variable type with the current one
// both need to be completely lowered (translated). Standard translation only goes one level deep.
// Generic arguments are not translated until they are needed by metadata writer.
//
// In order to get the fully lowered form we run the type symbols of stashed variables thru a deep translator
// that translates the symbol recursively.
_deepTranslator = new CSharpSymbolMatcher.DeepTranslator(sourceAssembly.GetSpecialType(SpecialType.System_Object));
}
示例8: PEAssemblyBuilder
public PEAssemblyBuilder(
SourceAssemblySymbol sourceAssembly,
Cci.ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources,
OutputKind outputKind,
EmitOptions emitOptions)
:base(sourceAssembly.DeclaringCompilation, (SourceModuleSymbol)sourceAssembly.Modules[0], serializationProperties, manifestResources, outputKind, emitOptions)
{
_sourceAssembly = sourceAssembly;
_metadataName = (emitOptions.OutputNameOverride == null) ? sourceAssembly.MetadataName : FileNameUtilities.ChangeExtension(emitOptions.OutputNameOverride, extension: null);
AssemblyOrModuleSymbolToModuleRefMap.Add(sourceAssembly, this);
}
示例9: EmitToStream
public static MemoryStream EmitToStream(this Compilation compilation, EmitOptions options = null, DiagnosticDescription[] expectedWarnings = null)
{
var stream = new MemoryStream();
var emitResult = compilation.Emit(stream, options: options);
Assert.True(emitResult.Success, "Diagnostics: " + string.Join(", ", emitResult.Diagnostics.Select(d => d.ToString())));
if (expectedWarnings != null)
{
emitResult.Diagnostics.Verify(expectedWarnings);
}
stream.Position = 0;
return stream;
}
示例10: EmitToImageReference
public static MetadataReference EmitToImageReference(
this Compilation comp,
EmitOptions options = null,
bool embedInteropTypes = false,
ImmutableArray<string> aliases = default(ImmutableArray<string>),
DiagnosticDescription[] expectedWarnings = null)
{
var image = comp.EmitToArray(options, expectedWarnings: expectedWarnings);
if (comp.Options.OutputKind == OutputKind.NetModule)
{
return ModuleMetadata.CreateFromImage(image).GetReference(display: comp.MakeSourceModuleName());
}
else
{
return AssemblyMetadata.CreateFromImage(image).GetReference(aliases: aliases, embedInteropTypes: embedInteropTypes, display: comp.MakeSourceAssemblySimpleName());
}
}
示例11: PEAssemblyBuilderBase
public PEAssemblyBuilderBase(
SourceAssemblySymbol sourceAssembly,
EmitOptions emitOptions,
OutputKind outputKind,
Cci.ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources,
ImmutableArray<NamedTypeSymbol> additionalTypes)
: base((SourceModuleSymbol)sourceAssembly.Modules[0], emitOptions, outputKind, serializationProperties, manifestResources)
{
Debug.Assert((object)sourceAssembly != null);
_sourceAssembly = sourceAssembly;
_additionalTypes = additionalTypes.NullToEmpty();
_metadataName = (emitOptions.OutputNameOverride == null) ? sourceAssembly.MetadataName : FileNameUtilities.ChangeExtension(emitOptions.OutputNameOverride, extension: null);
AssemblyOrModuleSymbolToModuleRefMap.Add(sourceAssembly, this);
}
示例12: EmitToArray
internal static ImmutableArray<byte> EmitToArray(
this Compilation compilation,
EmitOptions options = null,
CompilationTestData testData = null,
DiagnosticDescription[] expectedWarnings = null,
Stream pdbStream = null,
IMethodSymbol debugEntryPoint = null,
Stream sourceLinkStream = null,
IEnumerable<EmbeddedText> embeddedTexts = null)
{
var peStream = new MemoryStream();
if (pdbStream == null && compilation.Options.OptimizationLevel == OptimizationLevel.Debug && options?.DebugInformationFormat != DebugInformationFormat.Embedded)
{
if (MonoHelpers.IsRunningOnMono())
{
options = (options ?? EmitOptions.Default).WithDebugInformationFormat(DebugInformationFormat.PortablePdb);
}
pdbStream = new MemoryStream();
}
var emitResult = compilation.Emit(
peStream: peStream,
pdbStream: pdbStream,
xmlDocumentationStream: null,
win32Resources: null,
manifestResources: null,
options: options,
debugEntryPoint: debugEntryPoint,
sourceLinkStream: sourceLinkStream,
embeddedTexts: embeddedTexts,
testData: testData,
cancellationToken: default(CancellationToken));
Assert.True(emitResult.Success, "Diagnostics:\r\n" + string.Join("\r\n", emitResult.Diagnostics.Select(d => d.ToString())));
if (expectedWarnings != null)
{
emitResult.Diagnostics.Verify(expectedWarnings);
}
return peStream.ToImmutable();
}
示例13: Load
protected override Assembly Load(AssemblyName assemblyName)
{
Assembly assembly;
if (_assemblies.TryGetValue(assemblyName.Name, out assembly))
{
return assembly;
}
try
{
System.Console.WriteLine($"Load({assemblyName})");
ProjectId projectId;
if (_projects.TryGetValue(assemblyName.Name, out projectId))
{
var project = _workspace.CurrentSolution.GetProject(projectId);
System.Console.WriteLine($"Found project {project.AssemblyName}({(project.Id)})");
using (var assemblySymbols = new MemoryStream())
using (var assemblyStream = new MemoryStream())
{
var emitOptions = new EmitOptions().WithDebugInformationFormat(DebugInformationFormat.PortablePdb);
var compilation = project.GetCompilationAsync().GetAwaiter().GetResult();
var emitResult = compilation.Emit(assemblyStream, assemblySymbols, options: emitOptions);
if (emitResult.Success)
{
assemblyStream.Position = 0;
assemblySymbols.Position = 0;
return LoadFromStream(assemblyStream, assemblySymbols);
}
}
}
}
catch
{
return Default.LoadFromAssemblyName(assemblyName);
}
return null;
}
示例14: PEDeltaAssemblyBuilder
public PEDeltaAssemblyBuilder(
SourceAssemblySymbol sourceAssembly,
EmitOptions emitOptions,
OutputKind outputKind,
ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources,
EmitBaseline previousGeneration,
IEnumerable<SemanticEdit> edits,
Func<ISymbol, bool> isAddedSymbol)
: base(sourceAssembly, emitOptions, outputKind, serializationProperties, manifestResources, assemblySymbolMapper: null, additionalTypes: ImmutableArray<NamedTypeSymbol>.Empty)
{
var context = new EmitContext(this, null, new DiagnosticBag());
var module = previousGeneration.OriginalMetadata;
var compilation = sourceAssembly.DeclaringCompilation;
var metadataAssembly = compilation.GetBoundReferenceManager().CreatePEAssemblyForAssemblyMetadata(AssemblyMetadata.Create(module), MetadataImportOptions.All);
var metadataDecoder = new Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE.MetadataDecoder(metadataAssembly.PrimaryModule);
previousGeneration = EnsureInitialized(previousGeneration, metadataDecoder);
var matchToMetadata = new CSharpSymbolMatcher(previousGeneration.AnonymousTypeMap, sourceAssembly, context, metadataAssembly);
CSharpSymbolMatcher matchToPrevious = null;
if (previousGeneration.Ordinal > 0)
{
var previousAssembly = ((CSharpCompilation)previousGeneration.Compilation).SourceAssembly;
var previousContext = new EmitContext((PEModuleBuilder)previousGeneration.PEModuleBuilder, null, new DiagnosticBag());
matchToPrevious = new CSharpSymbolMatcher(
previousGeneration.AnonymousTypeMap,
sourceAssembly: sourceAssembly,
sourceContext: context,
otherAssembly: previousAssembly,
otherContext: previousContext,
otherSynthesizedMembersOpt: previousGeneration.SynthesizedMembers);
}
_previousDefinitions = new CSharpDefinitionMap(previousGeneration.OriginalMetadata.Module, edits, metadataDecoder, matchToMetadata, matchToPrevious);
_previousGeneration = previousGeneration;
_changes = new SymbolChanges(_previousDefinitions, edits, isAddedSymbol);
}
示例15: PEModuleBuilder
protected PEModuleBuilder(
PhpCompilation compilation,
SourceModuleSymbol sourceModule,
Cci.ModulePropertiesForSerialization serializationProperties,
IEnumerable<ResourceDescription> manifestResources,
OutputKind outputKind,
EmitOptions emitOptions)
{
Debug.Assert(sourceModule != null);
Debug.Assert(serializationProperties != null);
_compilation = compilation;
_sourceModule = sourceModule;
_serializationProperties = serializationProperties;
this.ManifestResources = manifestResources;
_outputKind = outputKind;
_emitOptions = emitOptions;
this.CompilationState = new CommonModuleCompilationState();
_debugDocuments = new ConcurrentDictionary<string, Cci.DebugSourceDocument>(compilation.IsCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase);
_synthesized = new SynthesizedManager(this);
AssemblyOrModuleSymbolToModuleRefMap.Add(sourceModule, this);
}