当前位置: 首页>>代码示例>>C#>>正文


C# Compilation类代码示例

本文整理汇总了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);
            }
        }
开发者ID:pheede,项目名称:roslyn,代码行数:25,代码来源:CA1008DiagnosticAnalyzer.cs

示例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));
     }
 }
开发者ID:riversky,项目名称:roslyn,代码行数:7,代码来源:CA2231DiagnosticAnalyzer.cs

示例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;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:31,代码来源:CA2214DiagnosticAnalyzer.cs

示例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));
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:25,代码来源:AbstractImplementInterfaceService.CodeAction_Property.cs

示例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));
     }
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:CA1060DiagnosticAnalyzer.cs

示例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;
                    }
                }
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:32,代码来源:CompilationWithAnalyzers.cs

示例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);
        }
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:7,代码来源:DoNotDirectlyAwaitATask.cs

示例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;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:28,代码来源:MetadataOnlyImage.cs

示例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;
            }
        }
开发者ID:hanin,项目名称:roslyn-analyzers,代码行数:31,代码来源:DoNotLockOnObjectsWithWeakIdentity.cs

示例10: TargetSymbolResolver

 public TargetSymbolResolver(Compilation compilation, TargetScope scope, string fullyQualifiedName)
 {
     this.compilation = compilation;
     this.scope = scope;
     this.name = fullyQualifiedName;
     this.index = 0;
 }
开发者ID:kislyuk,项目名称:roslyn,代码行数:7,代码来源:SuppressMessageAttributeState.TargetSymbolResolver.cs

示例11: ReferencedTypeCache

 internal ReferencedTypeCache(Compilation compilation,IFactoryAccess factoryAccess)
 {
     this.compilation = compilation;
      this.factoryAccess = factoryAccess;
      metadataLookup = new Dictionary<string, IType>();
      builtTrees = new Dictionary<SyntaxTree, IRoot>();
 }
开发者ID:KathleenDollard,项目名称:RoslynDOM,代码行数:7,代码来源:ReferencedTypeCache.cs

示例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);
        }
开发者ID:morganbr,项目名称:corert,代码行数:28,代码来源:CppWriter.cs

示例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);
     }
 }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:28,代码来源:OperatorsShouldHaveSymmetricalOverloads.Fixer.cs

示例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());
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:7,代码来源:AnalyzerDriver.CompilationData.cs

示例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));
     }
 }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:7,代码来源:MovePInvokesToNativeMethodsClass.cs


注:本文中的Compilation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。