本文整理汇总了C#中Microsoft.CodeAnalysis.CodeGen.CompilationTestData类的典型用法代码示例。如果您正苦于以下问题:C# CompilationTestData类的具体用法?C# CompilationTestData怎么用?C# CompilationTestData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationTestData类属于Microsoft.CodeAnalysis.CodeGen命名空间,在下文中一共展示了CompilationTestData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}");
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:35,代码来源:DynamicTests.cs
示例2: CompileGetLocals
internal abstract ReadOnlyCollection<byte> CompileGetLocals(
ArrayBuilder<LocalAndMethod> locals,
bool argumentsOnly,
ImmutableArray<Alias> aliases,
DiagnosticBag diagnostics,
out string typeName,
CompilationTestData testData);
开发者ID:GloryChou,项目名称:roslyn,代码行数:7,代码来源:EvaluationContextBase.cs
示例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
}
");
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:31,代码来源:ManagedAddressOfTests.cs
示例4: CompileExpression
internal abstract CompileResult CompileExpression(
string expr,
DkmEvaluationFlags compilationFlags,
ImmutableArray<Alias> aliases,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
开发者ID:GloryChou,项目名称:roslyn,代码行数:7,代码来源:EvaluationContextBase.cs
示例5: CompileAssignment
internal abstract CompileResult CompileAssignment(
string target,
string expr,
ImmutableArray<Alias> aliases,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
开发者ID:GloryChou,项目名称:roslyn,代码行数:7,代码来源:EvaluationContextBase.cs
示例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);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:31,代码来源:SynthesizedLocalsTests.cs
示例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;
}
}
开发者ID:rgani,项目名称:roslyn,代码行数:25,代码来源:EEAssemblyBuilder.cs
示例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();
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:29,代码来源:CompilationExtensions.cs
示例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;
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:35,代码来源:TestExtensions.cs
示例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
}
");
});
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:33,代码来源:ManagedAddressOfTests.cs
示例11: CompileAssignment
internal abstract CompileResult CompileAssignment(
InspectionContext inspectionContext,
string target,
string expr,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:EvaluationContextBase.cs
示例12: CompileExpression
internal abstract CompileResult CompileExpression(
InspectionContext inspectionContext,
string expr,
DkmEvaluationFlags compilationFlags,
DiagnosticBag diagnostics,
out ResultProperties resultProperties,
CompilationTestData testData);
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:EvaluationContextBase.cs
示例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();
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:32,代码来源:CompilationExtensions.cs
示例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);
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:10,代码来源:TestExtensions.cs
示例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);
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:10,代码来源:EvaluationContextBase.cs
示例16: CompilationDifference
public CompilationDifference(
ImmutableArray<byte> metadata,
ImmutableArray<byte> il,
Stream pdbStream,
EmitBaseline nextGeneration,
CompilationTestData testData,
EmitResult result)
{
this.MetadataBlob = metadata;
this.ILBlob = il;
this.Pdb = pdbStream;
this.NextGeneration = nextGeneration;
this.TestData = testData;
this.Result = result;
}
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:CompilationDifference.cs
示例17: CompilationDifference
public CompilationDifference(
ImmutableArray<byte> metadata,
ImmutableArray<byte> il,
Stream pdbStream,
CompilationTestData testData,
EmitDifferenceResult result,
ImmutableArray<MethodDefinitionHandle> methodHandles)
{
this.MetadataDelta = metadata;
this.ILDelta = il;
this.PdbDelta = pdbStream;
this.TestData = testData;
this.EmitResult = result;
this.UpdatedMethods = methodHandles;
}
开发者ID:daking2014,项目名称:roslyn,代码行数:15,代码来源:CompilationDifference.cs
示例18: 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();
}
开发者ID:jkotas,项目名称:roslyn,代码行数:44,代码来源:CompilationExtensions.cs
示例19: Win8RuntimeAssemblies
public void Win8RuntimeAssemblies()
{
var source =
@"class C
{
static void M(Windows.Storage.StorageFolder f, Windows.Foundation.Collections.PropertySet p)
{
}
}";
var compilation0 = CreateCompilationWithMscorlib(
source,
options: TestOptions.DebugDll,
assemblyName: ExpressionCompilerUtilities.GenerateUniqueName(),
references: WinRtRefs);
var runtimeAssemblies = ExpressionCompilerTestHelpers.GetRuntimeWinMds("Windows.Storage", "Windows.Foundation.Collections");
Assert.True(runtimeAssemblies.Length >= 2);
byte[] exeBytes;
byte[] pdbBytes;
ImmutableArray<MetadataReference> references;
compilation0.EmitAndGetReferences(out exeBytes, out pdbBytes, out references);
var runtime = CreateRuntimeInstance(
ExpressionCompilerUtilities.GenerateUniqueName(),
ImmutableArray.Create(MscorlibRef).Concat(runtimeAssemblies), // no reference to Windows.winmd
exeBytes,
new SymReader(pdbBytes));
var context = CreateMethodContext(runtime, "C.M");
ResultProperties resultProperties;
string error;
var testData = new CompilationTestData();
context.CompileExpression("(p == null) ? f : null", out resultProperties, out error, testData);
Assert.Null(error);
testData.GetMethodData("<>x.<>m0").VerifyIL(
@"{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.1
IL_0001: brfalse.s IL_0005
IL_0003: ldnull
IL_0004: ret
IL_0005: ldarg.0
IL_0006: ret
}");
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:43,代码来源:WinMdTests.cs
示例20: ExplicitEmbeddedType
public void ExplicitEmbeddedType()
{
var source =
@"using System.Runtime.InteropServices;
[TypeIdentifier]
[Guid(""863D5BC0-46A1-49AD-97AA-A5F0D441A9D8"")]
public interface I
{
object F();
}
class C
{
void M()
{
var o = (I)null;
}
static void Main()
{
(new C()).M();
}
}";
var compilation0 = CSharpTestBase.CreateCompilationWithMscorlib(
source,
options: TestOptions.DebugExe,
assemblyName: ExpressionCompilerUtilities.GenerateUniqueName());
var runtime = CreateRuntimeInstance(compilation0);
var context = CreateMethodContext(runtime, "C.M");
ResultProperties resultProperties;
string error;
var testData = new CompilationTestData();
var result = context.CompileExpression("this", out resultProperties, out error, testData);
Assert.Null(error);
testData.GetMethodData("<>x.<>m0").VerifyIL(
@"{
// Code size 2 (0x2)
.maxstack 1
.locals init (I V_0) //o
IL_0000: ldarg.0
IL_0001: ret
}");
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:41,代码来源:NoPIATests.cs
注:本文中的Microsoft.CodeAnalysis.CodeGen.CompilationTestData类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论