本文整理汇总了C#中CSharpCompilation类的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation类的具体用法?C# CSharpCompilation怎么用?C# CSharpCompilation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSharpCompilation类属于命名空间,在下文中一共展示了CSharpCompilation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RewriteLocal
internal override BoundExpression RewriteLocal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax)
{
var method = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetObjectAtAddressMethodName,
(c, n, s) =>
{
var parameterType = compilation.GetSpecialType(SpecialType.System_UInt64);
return new PlaceholderMethodSymbol(
c,
s,
n,
this.Type,
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)));
});
var argument = new BoundLiteral(
syntax,
Microsoft.CodeAnalysis.ConstantValue.Create(_address),
method.Parameters[0].Type);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create<BoundExpression>(argument));
Debug.Assert(call.Type == this.Type);
return call;
}
示例2: GetSymbolsForReferences
internal static AssemblySymbol[] GetSymbolsForReferences(
CSharpCompilation[] compilations = null,
byte[][] bytes = null,
MetadataReference[] mrefs = null,
CSharpCompilationOptions options = null)
{
var refs = new List<MetadataReference>();
if (compilations != null)
{
foreach (var c in compilations)
{
refs.Add(new CSharpCompilationReference(c));
}
}
if (bytes != null)
{
foreach (var b in bytes)
{
refs.Add(new MetadataImageReference(b.AsImmutableOrNull()));
}
}
if (mrefs != null)
{
refs.AddRange(mrefs);
}
var tc1 = CSharpCompilation.Create(assemblyName: "Dummy", options: options ?? TestOptions.ReleaseDll, syntaxTrees: new SyntaxTree[0], references: refs);
return (from @ref in refs select tc1.GetReferencedAssemblySymbol(@ref)).ToArray();
}
示例3: PlaceholderLocalRewriter
private PlaceholderLocalRewriter(CSharpCompilation compilation, EENamedTypeSymbol container, HashSet<LocalSymbol> declaredLocals, DiagnosticBag diagnostics)
{
_compilation = compilation;
_container = container;
_declaredLocals = declaredLocals;
_diagnostics = diagnostics;
}
示例4: Rewrite
internal static BoundNode Rewrite(CSharpCompilation compilation, EENamedTypeSymbol container, HashSet<LocalSymbol> declaredLocals, BoundNode node)
{
var builder = ArrayBuilder<BoundStatement>.GetInstance();
bool hasChanged;
// Rewrite top-level declarations only.
switch (node.Kind)
{
case BoundKind.LocalDeclaration:
RewriteLocalDeclaration(compilation, container, declaredLocals, builder, (BoundLocalDeclaration)node);
hasChanged = true;
break;
case BoundKind.MultipleLocalDeclarations:
foreach (var declaration in ((BoundMultipleLocalDeclarations)node).LocalDeclarations)
{
RewriteLocalDeclaration(compilation, container, declaredLocals, builder, declaration);
}
hasChanged = true;
break;
default:
hasChanged = false;
break;
}
if (hasChanged)
{
node = new BoundBlock(node.Syntax, ImmutableArray<LocalSymbol>.Empty, builder.ToImmutable()) { WasCompilerGenerated = true };
}
builder.Free();
return node;
}
示例5: ResolveBounds
/// <summary>
/// Determine the effective base type, effective interface set, and set of type
/// parameters (excluding cycles) from the type parameter constraints. Conflicts
/// within the constraints and constraint types are returned as diagnostics.
/// 'inherited' should be true if the type parameters are from an overridden
/// generic method. In those cases, additional constraint checks are applied.
/// </summary>
public static TypeParameterBounds ResolveBounds(
this TypeParameterSymbol typeParameter,
AssemblySymbol corLibrary,
ConsList<TypeParameterSymbol> inProgress,
ImmutableArray<TypeSymbol> constraintTypes,
bool inherited,
CSharpCompilation currentCompilation,
DiagnosticBag diagnostics)
{
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var bounds = typeParameter.ResolveBounds(corLibrary, inProgress, constraintTypes, inherited, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder);
if (useSiteDiagnosticsBuilder != null)
{
diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder);
}
foreach (var pair in diagnosticsBuilder)
{
diagnostics.Add(new CSDiagnostic(pair.DiagnosticInfo, pair.TypeParameter.Locations[0]));
}
diagnosticsBuilder.Free();
return bounds;
}
示例6: CheckCompilationSyntaxTrees
private static void CheckCompilationSyntaxTrees(CSharpCompilation compilation, params SyntaxTree[] expectedSyntaxTrees)
{
ImmutableArray<SyntaxTree> actualSyntaxTrees = compilation.SyntaxTrees;
int numTrees = expectedSyntaxTrees.Length;
Assert.Equal(numTrees, actualSyntaxTrees.Length);
for (int i = 0; i < numTrees; i++)
{
Assert.Equal(expectedSyntaxTrees[i], actualSyntaxTrees[i]);
}
for (int i = 0; i < numTrees; i++)
{
for (int j = 0; j < numTrees; j++)
{
Assert.Equal(Math.Sign(compilation.CompareSyntaxTreeOrdering(expectedSyntaxTrees[i], expectedSyntaxTrees[j])), Math.Sign(i.CompareTo(j)));
}
}
var types = expectedSyntaxTrees.Select(tree => compilation.GetSemanticModel(tree).GetDeclaredSymbol(tree.GetCompilationUnitRoot().Members.Single())).ToArray();
for (int i = 0; i < numTrees; i++)
{
for (int j = 0; j < numTrees; j++)
{
Assert.Equal(Math.Sign(compilation.CompareSourceLocations(types[i].Locations[0], types[j].Locations[0])), Math.Sign(i.CompareTo(j)));
}
}
}
示例7: RewriteLocalInternal
private static BoundExpression RewriteLocalInternal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax, LocalSymbol local)
{
var parameterType = compilation.GetSpecialType(SpecialType.System_String);
var getValueMethod = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetVariableValueMethodName,
(c, n, s) =>
{
var returnType = compilation.GetSpecialType(SpecialType.System_Object);
return new PlaceholderMethodSymbol(
c,
s,
n,
returnType,
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)));
});
var getAddressMethod = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetVariableAddressMethodName,
(c, n, s) =>
{
return new PlaceholderMethodSymbol(
c,
s,
n,
m => ImmutableArray.Create<TypeParameterSymbol>(new SimpleTypeParameterSymbol(m, 0, "<>T")),
m => m.TypeParameters[0], // return type is <>T&
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)),
returnValueIsByRef: true);
});
return new BoundPseudoVariable(
syntax,
local,
new ObjectIdExpressions(compilation, getValueMethod, getAddressMethod),
local.Type);
}
示例8: CompilationContext
/// <summary>
/// Create a context to compile expressions within a method scope.
/// </summary>
internal CompilationContext(
CSharpCompilation compilation,
MethodSymbol currentFrame,
ImmutableArray<LocalSymbol> locals,
InScopeHoistedLocals inScopeHoistedLocals,
MethodDebugInfo<TypeSymbol, LocalSymbol> methodDebugInfo,
CSharpSyntaxNode syntax)
{
Debug.Assert((syntax == null) || (syntax is ExpressionSyntax) || (syntax is LocalDeclarationStatementSyntax));
// TODO: syntax.SyntaxTree should probably be added to the compilation,
// but it isn't rooted by a CompilationUnitSyntax so it doesn't work (yet).
_currentFrame = currentFrame;
_syntax = syntax;
_methodNotType = !locals.IsDefault;
// NOTE: Since this is done within CompilationContext, it will not be cached.
// CONSIDER: The values should be the same everywhere in the module, so they
// could be cached.
// (Catch: what happens in a type context without a method def?)
this.Compilation = GetCompilationWithExternAliases(compilation, methodDebugInfo.ExternAliasRecords);
// Each expression compile should use a unique compilation
// to ensure expression-specific synthesized members can be
// added (anonymous types, for instance).
Debug.Assert(this.Compilation != compilation);
this.NamespaceBinder = CreateBinderChain(
this.Compilation,
(PEModuleSymbol)currentFrame.ContainingModule,
currentFrame.ContainingNamespace,
methodDebugInfo.ImportRecordGroups);
if (_methodNotType)
{
_locals = locals;
ImmutableArray<string> displayClassVariableNamesInOrder;
GetDisplayClassVariables(
currentFrame,
_locals,
inScopeHoistedLocals,
out displayClassVariableNamesInOrder,
out _displayClassVariables,
out _hoistedParameterNames);
Debug.Assert(displayClassVariableNamesInOrder.Length == _displayClassVariables.Count);
_localsForBinding = GetLocalsForBinding(_locals, displayClassVariableNamesInOrder, _displayClassVariables);
}
else
{
_locals = ImmutableArray<LocalSymbol>.Empty;
_displayClassVariables = ImmutableDictionary<string, DisplayClassVariable>.Empty;
_localsForBinding = ImmutableArray<LocalSymbol>.Empty;
}
// Assert that the cheap check for "this" is equivalent to the expensive check for "this".
Debug.Assert(
_displayClassVariables.ContainsKey(GeneratedNames.ThisProxyFieldName()) ==
_displayClassVariables.Values.Any(v => v.Kind == DisplayClassVariableKind.This));
}
示例9: RewriteLocalInternal
private static BoundExpression RewriteLocalInternal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax, LocalSymbol local)
{
return new BoundPseudoVariable(
syntax,
local,
new ObjectIdExpressions(compilation),
local.Type);
}
示例10: GetAwaitExpressionInfo
private AwaitExpressionInfo GetAwaitExpressionInfo(string text, out CSharpCompilation compilation, params DiagnosticDescription[] diagnostics)
{
var tree = Parse(text, options: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp5));
var comp = CreateCompilationWithMscorlib45(new SyntaxTree[] { tree }, new MetadataReference[] { SystemRef });
comp.VerifyDiagnostics(diagnostics);
compilation = comp;
var syntaxNode = (AwaitExpressionSyntax)tree.FindNodeOrTokenByKind(SyntaxKind.AwaitExpression).AsNode();
var treeModel = comp.GetSemanticModel(tree);
return treeModel.GetAwaitExpressionInfo(syntaxNode);
}
示例11: RewriteLocalDeclaration
private static void RewriteLocalDeclaration(
CSharpCompilation compilation,
EENamedTypeSymbol container,
HashSet<LocalSymbol> declaredLocals,
ArrayBuilder<BoundStatement> statements,
BoundLocalDeclaration node)
{
Debug.Assert(node.ArgumentsOpt.IsDefault);
var local = node.LocalSymbol;
var syntax = node.Syntax;
declaredLocals.Add(local);
var voidType = compilation.GetSpecialType(SpecialType.System_Void);
var objectType = compilation.GetSpecialType(SpecialType.System_Object);
var typeType = compilation.GetWellKnownType(WellKnownType.System_Type);
var stringType = compilation.GetSpecialType(SpecialType.System_String);
// <>CreateVariable(Type type, string name)
var method = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.CreateVariableMethodName,
(c, n, s) => new PlaceholderMethodSymbol(
c,
s,
n,
voidType,
m => ImmutableArray.Create<ParameterSymbol>(
new SynthesizedParameterSymbol(m, typeType, ordinal: 0, refKind: RefKind.None),
new SynthesizedParameterSymbol(m, stringType, ordinal: 1, refKind: RefKind.None))));
var type = new BoundTypeOfOperator(syntax, new BoundTypeExpression(syntax, aliasOpt: null, type: local.Type), null, typeType);
var name = new BoundLiteral(syntax, ConstantValue.Create(local.Name), stringType);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create<BoundExpression>(type, name));
statements.Add(new BoundExpressionStatement(syntax, call));
var initializer = node.InitializerOpt;
if (initializer != null)
{
// Generate assignment to local. The assignment will
// be rewritten in PlaceholderLocalRewriter.
var assignment = new BoundAssignmentOperator(
syntax,
new BoundLocal(syntax, local, constantValueOpt: null, type: local.Type),
initializer,
RefKind.None,
local.Type);
statements.Add(new BoundExpressionStatement(syntax, assignment));
}
}
示例12: RewriteLocal
internal override BoundExpression RewriteLocal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax, DiagnosticBag diagnostics)
{
var method = GetIntrinsicMethod(compilation, ExpressionCompilerConstants.GetReturnValueMethodName);
var argument = new BoundLiteral(
syntax,
Microsoft.CodeAnalysis.ConstantValue.Create(_index),
method.Parameters[0].Type);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create<BoundExpression>(argument));
return ConvertToLocalType(compilation, call, this.Type, diagnostics);
}
示例13: RewriteLocal
internal override BoundExpression RewriteLocal(CSharpCompilation compilation, EENamedTypeSymbol container, SyntaxNode syntax, DiagnosticBag diagnostics)
{
var method = GetIntrinsicMethod(compilation, ExpressionCompilerConstants.GetObjectAtAddressMethodName);
var argument = new BoundLiteral(
syntax,
Microsoft.CodeAnalysis.ConstantValue.Create(_address),
method.Parameters[0].Type);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create<BoundExpression>(argument));
Debug.Assert(call.Type == this.Type);
return call;
}
示例14: LambdaSymbol
public LambdaSymbol(
CSharpCompilation compilation,
Symbol containingSymbol,
UnboundLambda unboundLambda,
ImmutableArray<ParameterSymbol> delegateParameters,
TypeSymbol returnType)
{
this.containingSymbol = containingSymbol;
this.messageID = unboundLambda.Data.MessageID;
this.syntax = unboundLambda.Syntax;
this.returnType = returnType;
this.isSynthesized = unboundLambda.WasCompilerGenerated;
this.isAsync = unboundLambda.IsAsync;
// No point in making this lazy. We are always going to need these soon after creation of the symbol.
this.parameters = MakeParameters(compilation, unboundLambda, delegateParameters);
}
示例15: TypeDocumentationCommentTests
public TypeDocumentationCommentTests()
{
_compilation = CreateCompilationWithMscorlibAndDocumentationComments(@"enum Color { Red, Blue, Green }
namespace Acme
{
interface IProcess {...}
struct ValueType {...}
class Widget: IProcess
{
/// <summary>
/// Hello! Nested Class.
/// </summary>
public class NestedClass {...}
public interface IMenuItem {...}
public delegate void Del(int i);
public enum Direction { North, South, East, West }
}
class MyList<T>
{
class Helper<U,V> {...}
}
}");
_acmeNamespace = (NamespaceSymbol)_compilation.GlobalNamespace.GetMembers("Acme").Single();
_widgetClass = _acmeNamespace.GetTypeMembers("Widget").Single();
}