internal override CompileResult CompileExpression( string expr, DkmEvaluationFlags compilationFlags, ImmutableArray <Alias> aliases, DiagnosticBag diagnostics, out ResultProperties resultProperties, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData) { ReadOnlyCollection <string> formatSpecifiers; var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers); if (syntax == null) { resultProperties = default(ResultProperties); return(null); } var context = this.CreateCompilationContext(); var moduleBuilder = context.CompileExpression(syntax, TypeName, MethodName, aliases, testData, diagnostics, out var synthesizedMethod); if (moduleBuilder == null) { resultProperties = default(ResultProperties); return(null); } using (var stream = new MemoryStream()) { Cci.PeWriter.WritePeToStream( new EmitContext(moduleBuilder, null, diagnostics, metadataOnly: false, includePrivateMembers: true), context.MessageProvider, () => stream, getPortablePdbStreamOpt: null, nativePdbWriterOpt: null, pdbPathOpt: null, metadataOnly: false, isDeterministic: false, emitTestCoverageData: false, privateKeyOpt: null, cancellationToken: default(CancellationToken)); if (diagnostics.HasAnyErrors()) { resultProperties = default(ResultProperties); return(null); } Debug.Assert(synthesizedMethod.ContainingType.MetadataName == TypeName); Debug.Assert(synthesizedMethod.MetadataName == MethodName); resultProperties = synthesizedMethod.ResultProperties; return(new CSharpCompileResult( stream.ToArray(), synthesizedMethod, formatSpecifiers: formatSpecifiers)); } }
internal override CompileResult CompileAssignment( string target, string expr, ImmutableArray <Alias> aliases, DiagnosticBag diagnostics, out ResultProperties resultProperties, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData) { var assignment = target.ParseAssignment(expr, diagnostics); if (assignment == null) { resultProperties = default(ResultProperties); return(null); } var context = this.CreateCompilationContext(); var moduleBuilder = context.CompileAssignment(assignment, TypeName, MethodName, aliases, testData, diagnostics, out var synthesizedMethod); if (moduleBuilder == null) { resultProperties = default(ResultProperties); return(null); } using (var stream = new MemoryStream()) { Cci.PeWriter.WritePeToStream( new EmitContext(moduleBuilder, null, diagnostics), context.MessageProvider, () => stream, getPortablePdbStreamOpt: null, nativePdbWriterOpt: null, pdbPathOpt: null, allowMissingMethodBodies: false, isDeterministic: false, cancellationToken: default(CancellationToken)); if (diagnostics.HasAnyErrors()) { resultProperties = default(ResultProperties); return(null); } Debug.Assert(synthesizedMethod.ContainingType.MetadataName == TypeName); Debug.Assert(synthesizedMethod.MetadataName == MethodName); resultProperties = synthesizedMethod.ResultProperties; return(new CSharpCompileResult( stream.ToArray(), synthesizedMethod, formatSpecifiers: null)); } }
internal override CompileResult CompileExpression( string expr, DkmEvaluationFlags compilationFlags, ImmutableArray <Alias> aliases, DiagnosticBag diagnostics, out ResultProperties resultProperties, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData) { ReadOnlyCollection <string> formatSpecifiers; var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers); if (syntax == null) { resultProperties = default(ResultProperties); return(null); } var context = this.CreateCompilationContext(syntax); ResultProperties properties; var moduleBuilder = context.CompileExpression(TypeName, MethodName, aliases, testData, diagnostics, out properties); if (moduleBuilder == null) { resultProperties = default(ResultProperties); return(null); } using (var stream = new MemoryStream()) { Cci.PeWriter.WritePeToStream( new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics), context.MessageProvider, () => stream, getPortablePdbStreamOpt: null, nativePdbWriterOpt: null, pdbPathOpt: null, allowMissingMethodBodies: false, deterministic: false, cancellationToken: default(CancellationToken)); if (diagnostics.HasAnyErrors()) { resultProperties = default(ResultProperties); return(null); } resultProperties = properties; return(new CSharpCompileResult( stream.ToArray(), GetSynthesizedMethod(moduleBuilder), formatSpecifiers: formatSpecifiers)); } }
internal override CompileResult CompileAssignment( InspectionContext inspectionContext, string target, string expr, DiagnosticBag diagnostics, out ResultProperties resultProperties, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData) { var assignment = target.ParseAssignment(expr, diagnostics); if (assignment == null) { resultProperties = default(ResultProperties); return(default(CompileResult)); } var context = this.CreateCompilationContext(assignment); ResultProperties properties; var moduleBuilder = context.CompileAssignment(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties); if (moduleBuilder == null) { resultProperties = default(ResultProperties); return(default(CompileResult)); } using (var stream = new MemoryStream()) { Cci.PeWriter.WritePeToStream( new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics), context.MessageProvider, () => stream, nativePdbWriterOpt: null, pdbPathOpt: null, allowMissingMethodBodies: false, deterministic: false, cancellationToken: default(CancellationToken)); if (diagnostics.HasAnyErrors()) { resultProperties = default(ResultProperties); return(default(CompileResult)); } resultProperties = properties; return(new CompileResult( stream.ToArray(), typeName: TypeName, methodName: MethodName, formatSpecifiers: null)); } }
internal override ReadOnlyCollection <byte> CompileGetLocals( ArrayBuilder <LocalAndMethod> locals, bool argumentsOnly, ImmutableArray <Alias> aliases, DiagnosticBag diagnostics, out string typeName, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData) { var context = this.CreateCompilationContext(); var moduleBuilder = context.CompileGetLocals(TypeName, locals, argumentsOnly, aliases, testData, diagnostics); ReadOnlyCollection <byte> assembly = null; if ((moduleBuilder != null) && (locals.Count > 0)) { using (var stream = new MemoryStream()) { Cci.PeWriter.WritePeToStream( new EmitContext(moduleBuilder, null, diagnostics, metadataOnly: false, includePrivateMembers: true), context.MessageProvider, () => stream, getPortablePdbStreamOpt: null, nativePdbWriterOpt: null, pdbPathOpt: null, metadataOnly: false, isDeterministic: false, emitTestCoverageData: false, privateKeyOpt: null, cancellationToken: default(CancellationToken)); if (!diagnostics.HasAnyErrors()) { assembly = new ReadOnlyCollection <byte>(stream.ToArray()); } } } if (assembly == null) { locals.Clear(); assembly = s_emptyBytes; } typeName = TypeName; return(assembly); }
internal override ReadOnlyCollection <byte> CompileGetLocals( ArrayBuilder <LocalAndMethod> locals, bool argumentsOnly, out string typeName, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData = null) { var diagnostics = DiagnosticBag.GetInstance(); var context = this.CreateCompilationContext(null); var moduleBuilder = context.CompileGetLocals(TypeName, locals, argumentsOnly, testData, diagnostics); ReadOnlyCollection <byte> assembly = null; if ((moduleBuilder != null) && (locals.Count > 0)) { using (var stream = new MemoryStream()) { Cci.PeWriter.WritePeToStream( new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics), context.MessageProvider, () => stream, nativePdbWriterOpt: null, pdbPathOpt: null, allowMissingMethodBodies: false, deterministic: false, cancellationToken: default(CancellationToken)); if (!diagnostics.HasAnyErrors()) { assembly = new ReadOnlyCollection <byte>(stream.ToArray()); } } } diagnostics.Free(); if (assembly == null) { locals.Clear(); assembly = s_emptyBytes; } typeName = TypeName; return(assembly); }
internal override CompileResult CompileAssignment( InspectionContext inspectionContext, string target, string expr, DiagnosticFormatter formatter, out ResultProperties resultProperties, out string error, out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities, System.Globalization.CultureInfo preferredUICulture, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData) { var diagnostics = DiagnosticBag.GetInstance(); try { var assignment = target.ParseAssignment(expr, diagnostics); if (assignment == null) { error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities); resultProperties = default(ResultProperties); return(default(CompileResult)); } var context = this.CreateCompilationContext(assignment); ResultProperties properties; var moduleBuilder = context.CompileAssignment(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties); if (moduleBuilder == null) { error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities); resultProperties = default(ResultProperties); return(default(CompileResult)); } using (var stream = new MemoryStream()) { Cci.PeWriter.WritePeToStream( new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics), context.MessageProvider, stream, nativePdbWriterOpt: null, allowMissingMethodBodies: false, deterministic: false, cancellationToken: default(CancellationToken)); if (diagnostics.HasAnyErrors()) { error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities); resultProperties = default(ResultProperties); return(default(CompileResult)); } resultProperties = properties; error = null; missingAssemblyIdentities = ImmutableArray <AssemblyIdentity> .Empty; return(new CompileResult( stream.ToArray(), typeName: TypeName, methodName: MethodName, formatSpecifiers: null)); } } finally { diagnostics.Free(); } }