本文整理汇总了C#中CSharpCompilation.ConstructModuleSerializationProperties方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation.ConstructModuleSerializationProperties方法的具体用法?C# CSharpCompilation.ConstructModuleSerializationProperties怎么用?C# CSharpCompilation.ConstructModuleSerializationProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpCompilation
的用法示例。
在下文中一共展示了CSharpCompilation.ConstructModuleSerializationProperties方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitDifference
internal static EmitDifferenceResult EmitDifference(
CSharpCompilation compilation,
EmitBaseline baseline,
IEnumerable<SemanticEdit> edits,
Func<ISymbol, bool> isAddedSymbol,
Stream metadataStream,
Stream ilStream,
Stream pdbStream,
ICollection<MethodDefinitionHandle> updatedMethods,
CompilationTestData testData,
CancellationToken cancellationToken)
{
Guid moduleVersionId;
try
{
moduleVersionId = baseline.OriginalMetadata.GetModuleVersionId();
}
catch (BadImageFormatException)
{
// TODO:
// return MakeEmitResult(success: false, diagnostics: ..., baseline: null);
throw;
}
var diagnostics = DiagnosticBag.GetInstance();
var emitOptions = EmitOptions.Default;
string runtimeMDVersion = compilation.GetRuntimeMetadataVersion(emitOptions, diagnostics);
var serializationProperties = compilation.ConstructModuleSerializationProperties(emitOptions, runtimeMDVersion, moduleVersionId);
var manifestResources = SpecializedCollections.EmptyEnumerable<ResourceDescription>();
var moduleBeingBuilt = new PEDeltaAssemblyBuilder(
compilation.SourceAssembly,
emitOptions: emitOptions,
outputKind: compilation.Options.OutputKind,
serializationProperties: serializationProperties,
manifestResources: manifestResources,
previousGeneration: baseline,
edits: edits,
isAddedSymbol: isAddedSymbol);
if (testData != null)
{
moduleBeingBuilt.SetMethodTestData(testData.Methods);
testData.Module = moduleBeingBuilt;
}
var definitionMap = moduleBeingBuilt.PreviousDefinitions;
var changes = moduleBeingBuilt.Changes;
EmitBaseline newBaseline = null;
if (compilation.Compile(
moduleBeingBuilt,
win32Resources: null,
xmlDocStream: null,
emittingPdb: true,
diagnostics: diagnostics,
filterOpt: changes.RequiresCompilation,
cancellationToken: cancellationToken))
{
// Map the definitions from the previous compilation to the current compilation.
// This must be done after compiling above since synthesized definitions
// (generated when compiling method bodies) may be required.
var mappedBaseline = MapToCompilation(compilation, moduleBeingBuilt);
newBaseline = compilation.SerializeToDeltaStreams(
moduleBeingBuilt,
mappedBaseline,
definitionMap,
changes,
metadataStream,
ilStream,
pdbStream,
updatedMethods,
diagnostics,
testData?.SymWriterFactory,
cancellationToken);
}
return new EmitDifferenceResult(
success: newBaseline != null,
diagnostics: diagnostics.ToReadOnlyAndFree(),
baseline: newBaseline);
}
示例2: CreateModuleBuilder
private static EEAssemblyBuilder CreateModuleBuilder(
CSharpCompilation compilation,
ImmutableArray<MethodSymbol> methods,
ImmutableArray<NamedTypeSymbol> additionalTypes,
EENamedTypeSymbol synthesizedType,
Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData,
DiagnosticBag diagnostics)
{
// Each assembly must have a unique name.
var emitOptions = new EmitOptions(outputNameOverride: ExpressionCompilerUtilities.GenerateUniqueName());
var dynamicOperationContextType = GetNonDisplayClassContainer(synthesizedType.SubstitutedSourceType);
string runtimeMetadataVersion = compilation.GetRuntimeMetadataVersion(emitOptions, diagnostics);
var serializationProperties = compilation.ConstructModuleSerializationProperties(emitOptions, runtimeMetadataVersion);
return new EEAssemblyBuilder(compilation.SourceAssembly, emitOptions, methods, serializationProperties, additionalTypes, dynamicOperationContextType, testData);
}
示例3: EmitDifference
internal static EmitDifferenceResult EmitDifference(
CSharpCompilation compilation,
EmitBaseline baseline,
IEnumerable<SemanticEdit> edits,
Func<ISymbol, bool> isAddedSymbol,
Stream metadataStream,
Stream ilStream,
Stream pdbStream,
ICollection<MethodDefinitionHandle> updatedMethods,
CompilationTestData testData,
CancellationToken cancellationToken)
{
Guid moduleVersionId;
try
{
moduleVersionId = baseline.OriginalMetadata.GetModuleVersionId();
}
catch (BadImageFormatException)
{
// TODO:
// return MakeEmitResult(success: false, diagnostics: ..., baseline: null);
throw;
}
var pdbName = FileNameUtilities.ChangeExtension(compilation.SourceModule.Name, "pdb");
var diagnostics = DiagnosticBag.GetInstance();
var emitOptions = EmitOptions.Default;
string runtimeMDVersion = compilation.GetRuntimeMetadataVersion(emitOptions, diagnostics);
var serializationProperties = compilation.ConstructModuleSerializationProperties(emitOptions, runtimeMDVersion, moduleVersionId);
var manifestResources = SpecializedCollections.EmptyEnumerable<ResourceDescription>();
var moduleBeingBuilt = new PEDeltaAssemblyBuilder(
compilation.SourceAssembly,
emitOptions: emitOptions,
outputKind: compilation.Options.OutputKind,
serializationProperties: serializationProperties,
manifestResources: manifestResources,
previousGeneration: baseline,
edits: edits,
isAddedSymbol: isAddedSymbol);
if (testData != null)
{
moduleBeingBuilt.SetMethodTestData(testData.Methods);
testData.Module = moduleBeingBuilt;
}
baseline = moduleBeingBuilt.PreviousGeneration;
var definitionMap = moduleBeingBuilt.PreviousDefinitions;
var changes = moduleBeingBuilt.Changes;
if (compilation.Compile(
moduleBeingBuilt,
win32Resources: null,
xmlDocStream: null,
generateDebugInfo: true,
diagnostics: diagnostics,
filterOpt: changes.RequiresCompilation,
cancellationToken: cancellationToken))
{
// Map the definitions from the previous compilation to the current compilation.
// This must be done after compiling above since synthesized definitions
// (generated when compiling method bodies) may be required.
baseline = MapToCompilation(compilation, moduleBeingBuilt);
using (var pdbWriter = new Cci.PdbWriter(pdbName, pdbStream, (testData != null) ? testData.SymWriterFactory : null))
{
var context = new EmitContext(moduleBeingBuilt, null, diagnostics);
var encId = Guid.NewGuid();
try
{
var writer = new DeltaMetadataWriter(
context,
compilation.MessageProvider,
baseline,
encId,
definitionMap,
changes,
cancellationToken);
Cci.MetadataSizes metadataSizes;
writer.WriteMetadataAndIL(pdbWriter, metadataStream, ilStream, out metadataSizes);
writer.GetMethodTokens(updatedMethods);
bool hasErrors = diagnostics.HasAnyErrors();
return new EmitDifferenceResult(
success: !hasErrors,
diagnostics: diagnostics.ToReadOnlyAndFree(),
baseline: hasErrors ? null : writer.GetDelta(baseline, compilation, encId, metadataSizes));
}
catch (Cci.PdbWritingException e)
{
diagnostics.Add(ErrorCode.FTL_DebugEmitFailure, Location.None, e.Message);
}
catch (PermissionSetFileReadException e)
{
//.........这里部分代码省略.........