本文整理汇总了C#中Microsoft.CodeAnalysis.CodeGen.CompilationTestData类的典型用法代码示例。如果您正苦于以下问题:C# CompilationTestData类的具体用法?C# CompilationTestData怎么用?C# CompilationTestData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationTestData类属于Microsoft.CodeAnalysis.CodeGen命名空间,在下文中一共展示了CompilationTestData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Local_Array
public void Local_Array()
{
var source =
@"class C
{
static void M()
{
dynamic[] d = new dynamic[1];
}
static dynamic ForceDynamicAttribute()
{
return null;
}
}";
var comp = CreateCompilationWithMscorlib(source, new[] { SystemCoreRef, CSharpRef }, options: TestOptions.DebugDll);
var runtime = CreateRuntimeInstance(comp);
var context = CreateMethodContext(runtime, "C.M");
var testData = new CompilationTestData();
var locals = ArrayBuilder<LocalAndMethod>.GetInstance();
string typeName;
var assembly = context.CompileGetLocals(locals, argumentsOnly: false, typeName: out typeName, testData: testData);
Assert.Equal(1, locals.Count);
var method = testData.Methods.Single().Value.Method;
AssertHasDynamicAttribute(method);
Assert.Equal(TypeKind.Dynamic, ((ArrayTypeSymbol)method.ReturnType).ElementType.TypeKind);
VerifyLocal(testData, typeName, locals[0], "<>m0", "d", expectedILOpt:
@"{
// Code size 2 (0x2)
.maxstack 1
.locals init (dynamic[] V_0) //d
IL_0000: ldloc.0
IL_0001: ret
}");
}
示例2: CompileGetLocals
internal abstract ReadOnlyCollection<byte> CompileGetLocals(
ArrayBuilder<LocalAndMethod> locals,
bool argumentsOnly,
ImmutableArray<Alias> aliases,
DiagnosticBag diagnostics,
out string typeName,
CompilationTestData testData);
示例3: AddressOfParameter
public void AddressOfParameter()
{
var source =
@"class C
{
void M(string s)
{
}
}";
var comp = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
var runtime = CreateRuntimeInstance(comp);
var context = CreateMethodContext(
runtime,
methodName: "C.M");
var testData = new CompilationTestData();
string error;
context.CompileExpression("&s", out error, testData);
Assert.Null(error);
var methodData = testData.GetMethodData("<>x.<>m0");
AssertIsIntPtrPointer(methodData.Method.ReturnType);
methodData.VerifyIL(@"
{
// Code size 4 (0x4)
.maxstack 1
IL_0000: ldarga.s V_1
IL_0002: conv.u
IL_0003: ret
}
");
}
示例4: CompileExpression
internal abstract CompileResult CompileExpression(
string expr,
DkmEvaluationFlags compilationFlags,
ImmutableArray<Alias> aliases,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
示例5: CompileAssignment
internal abstract CompileResult CompileAssignment(
string target,
string expr,
ImmutableArray<Alias> aliases,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
示例6: DebugOnly
public void DebugOnly()
{
var source =
@"class C
{
static System.IDisposable F()
{
return null;
}
static void M()
{
lock (F()) { }
using (F()) { }
}
}";
var debug = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
var release = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseDll);
CompilationTestData testData;
ImmutableArray<string> names;
testData = new CompilationTestData();
debug.EmitToArray(testData: testData);
names = GetLocalNames(testData.GetMethodData("C.M"));
AssertEx.Equal(new string[] { "CS$2$0000", "CS$520$0001", "CS$3$0002" }, names);
testData = new CompilationTestData();
release.EmitToArray(testData: testData);
names = GetLocalNames(testData.GetMethodData("C.M"));
AssertEx.Equal(new string[] { null, null }, names);
}
示例7: 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;
}
}
示例8: EmitToArray
internal static ImmutableArray<byte> EmitToArray(
this Compilation compilation,
bool metadataOnly = false,
CompilationTestData testData = null,
DiagnosticDescription[] expectedWarnings = null)
{
var stream = new MemoryStream();
var emitResult = compilation.Emit(
peStream: stream,
outputName: null,
pdbFilePath: null,
pdbStream: null,
xmlDocumentationStream: null,
cancellationToken: default(CancellationToken),
win32Resources: null,
manifestResources: null,
metadataOnly: metadataOnly,
testData: testData);
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();
}
示例9: CompileAssignment
internal static CompileResult CompileAssignment(
this EvaluationContextBase context,
string target,
string expr,
out string error,
CompilationTestData testData = null,
DiagnosticFormatter formatter = null)
{
ResultProperties resultProperties;
ImmutableArray<AssemblyIdentity> missingAssemblyIdentities;
var result = context.CompileAssignment(
DefaultInspectionContext.Instance,
target,
expr,
formatter ?? DiagnosticFormatter.Instance,
out resultProperties,
out error,
out missingAssemblyIdentities,
EnsureEnglishUICulture.PreferredOrNull,
testData);
Assert.Empty(missingAssemblyIdentities);
// This is a crude way to test the language, but it's convenient to share this test helper.
var isCSharp = context.GetType().Namespace.IndexOf("csharp", StringComparison.OrdinalIgnoreCase) >= 0;
var expectedFlags = error != null
? DkmClrCompilationResultFlags.None
: isCSharp
? DkmClrCompilationResultFlags.PotentialSideEffect
: DkmClrCompilationResultFlags.PotentialSideEffect | DkmClrCompilationResultFlags.ReadOnlyResult;
Assert.Equal(expectedFlags, resultProperties.Flags);
Assert.Equal(default(DkmEvaluationResultCategory), resultProperties.Category);
Assert.Equal(default(DkmEvaluationResultAccessType), resultProperties.AccessType);
Assert.Equal(default(DkmEvaluationResultStorageType), resultProperties.StorageType);
Assert.Equal(default(DkmEvaluationResultTypeModifierFlags), resultProperties.ModifierFlags);
return result;
}
示例10: AddressOfLocal
public void AddressOfLocal()
{
var source =
@"class C
{
void M()
{
string s = ""hello"";
}
}";
var comp = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "C.M");
var testData = new CompilationTestData();
string error;
context.CompileExpression("&s", out error, testData);
Assert.Null(error);
var methodData = testData.GetMethodData("<>x.<>m0");
AssertIsIntPtrPointer(methodData.Method.ReturnType);
methodData.VerifyIL(@"
{
// Code size 4 (0x4)
.maxstack 1
.locals init (string V_0) //s
IL_0000: ldloca.s V_0
IL_0002: conv.u
IL_0003: ret
}
");
});
}
示例11: CompileAssignment
internal abstract CompileResult CompileAssignment(
InspectionContext inspectionContext,
string target,
string expr,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
示例12: CompileExpression
internal abstract CompileResult CompileExpression(
InspectionContext inspectionContext,
string expr,
DkmEvaluationFlags compilationFlags,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
示例13: 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();
}
示例14: CompileExpression
internal static CompileResult CompileExpression(
this EvaluationContextBase context,
string expr,
out string error,
CompilationTestData testData = null,
DiagnosticFormatter formatter = null)
{
ResultProperties resultProperties;
return CompileExpression(context, expr, out resultProperties, out error, testData, formatter);
}
示例15: CompileAssignment
internal abstract CompileResult CompileAssignment(
InspectionContext inspectionContext,
string target,
string expr,
DiagnosticFormatter formatter,
out ResultProperties resultProperties,
out string error,
out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities,
CultureInfo preferredUICulture,
CompilationTestData testData);