本文整理汇总了C#中Compilation类的典型用法代码示例。如果您正苦于以下问题:C# Compilation类的具体用法?C# Compilation怎么用?C# Compilation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Compilation类属于命名空间,在下文中一共展示了Compilation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
if (symbol.TypeKind != TypeKind.Enum)
{
return;
}
var flagsAttribute = WellKnownTypes.FlagsAttribute(compilation);
if (flagsAttribute == null)
{
return;
}
var zeroValuedFields = GetZeroValuedFields(symbol).ToImmutableArray();
bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass == flagsAttribute);
if (hasFlagsAttribute)
{
CheckFlags(symbol, zeroValuedFields, addDiagnostic);
}
else
{
CheckNonFlags(symbol, zeroValuedFields, addDiagnostic);
}
}
示例2: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol namedTypeSymbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
if (namedTypeSymbol.IsValueType && IsOverridesEquals(namedTypeSymbol) && !IsEqualityOperatorImplemented(namedTypeSymbol))
{
addDiagnostic(namedTypeSymbol.CreateDiagnostic(Rule));
}
}
示例3: ShouldOmitThisDiagnostic
private static bool ShouldOmitThisDiagnostic(ISymbol symbol, Compilation compilation)
{
// This diagnostic is only relevant in constructors.
// TODO: should this apply to instance field initializers for VB?
var m = symbol as IMethodSymbol;
if (m == null || m.MethodKind != MethodKind.Constructor)
{
return true;
}
var containingType = m.ContainingType;
if (containingType == null)
{
return true;
}
// special case ASP.NET and WinForms constructors
INamedTypeSymbol webUiControlType = compilation.GetTypeByMetadataName("System.Web.UI.Control");
if (containingType.Inherits(webUiControlType))
{
return true;
}
INamedTypeSymbol windowsFormsControlType = compilation.GetTypeByMetadataName("System.Windows.Forms.Control");
if (containingType.Inherits(windowsFormsControlType))
{
return true;
}
return false;
}
示例4: GenerateSetAccessor
private IMethodSymbol GenerateSetAccessor(
Compilation compilation,
IPropertySymbol property,
Accessibility accessibility,
bool generateAbstractly,
bool useExplicitInterfaceSymbol,
INamedTypeSymbol[] attributesToRemove,
CancellationToken cancellationToken)
{
if (property.SetMethod == null)
{
return null;
}
var setMethod = property.SetMethod.RemoveInaccessibleAttributesAndAttributesOfTypes(
this.State.ClassOrStructType,
attributesToRemove);
return CodeGenerationSymbolFactory.CreateAccessorSymbol(
setMethod,
attributes: null,
accessibility: accessibility,
explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.SetMethod : null,
statements: GetSetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));
}
示例5: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
{
if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
{
addDiagnostic(symbol.CreateDiagnostic(Rule));
}
}
示例6: GetEffectiveDiagnostics
/// <summary>
/// Given a set of compiler or <see cref="DiagnosticAnalyzer"/> generated <paramref name="diagnostics"/>, returns the effective diagnostics after applying the below filters:
/// 1) <see cref="CompilationOptions.SpecificDiagnosticOptions"/> specified for the given <paramref name="compilation"/>.
/// 2) <see cref="CompilationOptions.GeneralDiagnosticOption"/> specified for the given <paramref name="compilation"/>.
/// 3) Diagnostic suppression through applied <see cref="System.Diagnostics.CodeAnalysis.SuppressMessageAttribute"/>.
/// 4) Pragma directives for the given <paramref name="compilation"/>.
/// </summary>
public static IEnumerable<Diagnostic> GetEffectiveDiagnostics(IEnumerable<Diagnostic> diagnostics, Compilation compilation)
{
if (diagnostics == null)
{
throw new ArgumentNullException(nameof(diagnostics));
}
if (compilation == null)
{
throw new ArgumentNullException(nameof(compilation));
}
var suppressMessageState = AnalyzerDriver.SuppressMessageStateByCompilation.GetValue(compilation, (c) => new SuppressMessageAttributeState(c));
foreach (var diagnostic in diagnostics.ToImmutableArray())
{
if (diagnostic != null)
{
var effectiveDiagnostic = compilation.FilterDiagnostic(diagnostic);
if (effectiveDiagnostic != null && !suppressMessageState.IsDiagnosticSuppressed(effectiveDiagnostic))
{
yield return effectiveDiagnostic;
}
}
}
}
示例7: GetTaskTypes
private static ImmutableArray<INamedTypeSymbol> GetTaskTypes(Compilation compilation)
{
INamedTypeSymbol taskType = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
INamedTypeSymbol taskOfTType = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1");
return ImmutableArray.Create(taskType, taskOfTType);
}
示例8: Create
public static MetadataOnlyImage Create(ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken))
{
// TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that
// we don't allocate anything for skeleton assembly.
using (var stream = SerializableBytes.CreateWritableStream())
{
// note: cloning compilation so we don't retain all the generated symbols after its emitted.
// * REVIEW * is cloning clone p2p reference compilation as well?
var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken);
if (emitResult.Success)
{
var storage = service.CreateTemporaryStreamStorage(cancellationToken);
stream.Position = 0;
storage.WriteStream(stream, cancellationToken);
return new MetadataOnlyImage(storage, compilation.AssemblyName);
}
}
}
return Empty;
}
示例9: TypeHasWeakIdentity
private bool TypeHasWeakIdentity(ITypeSymbol type, Compilation compilation)
{
switch (type.TypeKind)
{
case TypeKind.Array:
var arrayType = type as IArrayTypeSymbol;
return arrayType != null && IsPrimitiveType(arrayType.ElementType);
case TypeKind.Class:
case TypeKind.TypeParameter:
INamedTypeSymbol marshalByRefObjectTypeSymbol = compilation.GetTypeByMetadataName("System.MarshalByRefObject");
INamedTypeSymbol executionEngineExceptionTypeSymbol = compilation.GetTypeByMetadataName("System.ExecutionEngineException");
INamedTypeSymbol outOfMemoryExceptionTypeSymbol = compilation.GetTypeByMetadataName("System.OutOfMemoryException");
INamedTypeSymbol stackOverflowExceptionTypeSymbol = compilation.GetTypeByMetadataName("System.StackOverflowException");
INamedTypeSymbol memberInfoTypeSymbol = compilation.GetTypeByMetadataName("System.Reflection.MemberInfo");
INamedTypeSymbol parameterInfoTypeSymbol = compilation.GetTypeByMetadataName("System.Reflection.ParameterInfo");
INamedTypeSymbol threadTypeSymbol = compilation.GetTypeByMetadataName("System.Threading.Thread");
return
type.SpecialType == SpecialType.System_String ||
type.Equals(executionEngineExceptionTypeSymbol) ||
type.Equals(outOfMemoryExceptionTypeSymbol) ||
type.Equals(stackOverflowExceptionTypeSymbol) ||
type.Inherits(marshalByRefObjectTypeSymbol) ||
type.Inherits(memberInfoTypeSymbol) ||
type.Inherits(parameterInfoTypeSymbol) ||
type.Inherits(threadTypeSymbol);
// What about struct types?
default:
return false;
}
}
示例10: TargetSymbolResolver
public TargetSymbolResolver(Compilation compilation, TargetScope scope, string fullyQualifiedName)
{
this.compilation = compilation;
this.scope = scope;
this.name = fullyQualifiedName;
this.index = 0;
}
示例11: ReferencedTypeCache
internal ReferencedTypeCache(Compilation compilation,IFactoryAccess factoryAccess)
{
this.compilation = compilation;
this.factoryAccess = factoryAccess;
metadataLookup = new Dictionary<string, IType>();
builtTrees = new Dictionary<SyntaxTree, IRoot>();
}
示例12: CppWriter
public CppWriter(Compilation compilation)
{
_compilation = compilation;
SetWellKnownTypeSignatureName(WellKnownType.Void, "void");
SetWellKnownTypeSignatureName(WellKnownType.Boolean, "uint8_t");
SetWellKnownTypeSignatureName(WellKnownType.Char, "uint16_t");
SetWellKnownTypeSignatureName(WellKnownType.SByte, "int8_t");
SetWellKnownTypeSignatureName(WellKnownType.Byte, "uint8_t");
SetWellKnownTypeSignatureName(WellKnownType.Int16, "int16_t");
SetWellKnownTypeSignatureName(WellKnownType.UInt16, "uint16_t");
SetWellKnownTypeSignatureName(WellKnownType.Int32, "int32_t");
SetWellKnownTypeSignatureName(WellKnownType.UInt32, "uint32_t");
SetWellKnownTypeSignatureName(WellKnownType.Int64, "int64_t");
SetWellKnownTypeSignatureName(WellKnownType.UInt64, "uint64_t");
SetWellKnownTypeSignatureName(WellKnownType.IntPtr, "intptr_t");
SetWellKnownTypeSignatureName(WellKnownType.UIntPtr, "uintptr_t");
SetWellKnownTypeSignatureName(WellKnownType.Single, "float");
SetWellKnownTypeSignatureName(WellKnownType.Double, "double");
// TODO: For now, ensure that all types/methods referenced by unmanaged helpers are present
var stringType = _compilation.TypeSystemContext.GetWellKnownType(WellKnownType.String);
AddInstanceFields(stringType);
var stringArrayType = stringType.MakeArrayType();
_compilation.AddType(stringArrayType);
_compilation.MarkAsConstructed(stringArrayType);
}
示例13: GetInvertedStatement
private SyntaxNode GetInvertedStatement(
SyntaxGenerator generator, IMethodSymbol containingOperator, Compilation compilation)
{
if (containingOperator.Name == WellKnownMemberNames.EqualityOperatorName)
{
return generator.ReturnStatement(
generator.LogicalNotExpression(
generator.ValueEqualsExpression(
generator.IdentifierName(containingOperator.Parameters[0].Name),
generator.IdentifierName(containingOperator.Parameters[1].Name))));
}
else if (containingOperator.Name == WellKnownMemberNames.InequalityOperatorName)
{
return generator.ReturnStatement(
generator.LogicalNotExpression(
generator.ValueNotEqualsExpression(
generator.IdentifierName(containingOperator.Parameters[0].Name),
generator.IdentifierName(containingOperator.Parameters[1].Name))));
}
else
{
// If it's a < > <= or >= operator then we can't simply invert a call
// to the existing operator. i.e. the body of the "<" method should *not* be:
// return !(a > b);
// Just provide a throwing impl for now.
return generator.DefaultMethodStatement(compilation);
}
}
示例14: CompilationData
public CompilationData(Compilation comp)
{
_semanticModelsMap = new Dictionary<SyntaxTree, SemanticModel>();
this.SuppressMessageAttributeState = new SuppressMessageAttributeState(comp);
_declarationAnalysisDataMap = new Dictionary<SyntaxReference, DeclarationAnalysisData>();
_declarationAnalysisDataPool = new ObjectPool<DeclarationAnalysisData>(() => new DeclarationAnalysisData());
}
示例15: AnalyzeSymbol
private void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic)
{
if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
{
addDiagnostic(symbol.CreateDiagnostic(Rule));
}
}