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


C# ISymbol.IsKind方法代码示例

本文整理汇总了C#中ISymbol.IsKind方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.IsKind方法的具体用法?C# ISymbol.IsKind怎么用?C# ISymbol.IsKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISymbol的用法示例。


在下文中一共展示了ISymbol.IsKind方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsSymbolAccessibleCore

        /// <summary>
        /// Checks if 'symbol' is accessible from within 'within', which must be a INamedTypeSymbol
        /// or an IAssemblySymbol.  If 'symbol' is accessed off of an expression then
        /// 'throughTypeOpt' is the type of that expression. This is needed to properly do protected
        /// access checks. Sets "failedThroughTypeCheck" to true if this protected check failed.
        /// </summary>
        //// NOTE(cyrusn): I expect this function to be called a lot.  As such, I do not do any memory
        //// allocations in the function itself (including not making any iterators).  This does mean
        //// that certain helper functions that we'd like to call are inlined in this method to
        //// prevent the overhead of returning collections or enumerators.  
        private static bool IsSymbolAccessibleCore(
            ISymbol symbol,
            ISymbol within,  // must be assembly or named type symbol
            ITypeSymbol throughTypeOpt,
            out bool failedThroughTypeCheck)
        {
            Contract.ThrowIfNull(symbol);
            Contract.ThrowIfNull(within);
            Contract.Requires(within is INamedTypeSymbol || within is IAssemblySymbol);

            failedThroughTypeCheck = false;
            var withinAssembly = (within as IAssemblySymbol) ?? ((INamedTypeSymbol)within).ContainingAssembly;

            switch (symbol.Kind)
            {
                case SymbolKind.Alias:
                    return IsSymbolAccessibleCore(((IAliasSymbol)symbol).Target, within, throughTypeOpt, out failedThroughTypeCheck);

                case SymbolKind.ArrayType:
                    return IsSymbolAccessibleCore(((IArrayTypeSymbol)symbol).ElementType, within, null, out failedThroughTypeCheck);

                case SymbolKind.PointerType:
                    return IsSymbolAccessibleCore(((IPointerTypeSymbol)symbol).PointedAtType, within, null, out failedThroughTypeCheck);

                case SymbolKind.NamedType:
                    return IsNamedTypeAccessible((INamedTypeSymbol)symbol, within);

                case SymbolKind.ErrorType:
                    return true;

                case SymbolKind.TypeParameter:
                case SymbolKind.Parameter:
                case SymbolKind.Local:
                case SymbolKind.Label:
                case SymbolKind.Namespace:
                case SymbolKind.DynamicType:
                case SymbolKind.Assembly:
                case SymbolKind.NetModule:
                case SymbolKind.RangeVariable:
                    // These types of symbols are always accessible (if visible).
                    return true;

                case SymbolKind.Method:
                case SymbolKind.Property:
                case SymbolKind.Field:
                case SymbolKind.Event:
                    if (symbol.IsStatic)
                    {
                        // static members aren't accessed "through" an "instance" of any type.  So we
                        // null out the "through" instance here.  This ensures that we'll understand
                        // accessing protected statics properly.
                        throughTypeOpt = null;
                    }

                    // If this is a synthesized operator of dynamic, it's always accessible.
                    if (symbol.IsKind(SymbolKind.Method) &&
                        ((IMethodSymbol)symbol).MethodKind == MethodKind.BuiltinOperator &&
                        symbol.ContainingSymbol.IsKind(SymbolKind.DynamicType))
                    {
                        return true;
                    }

                    // If it's a synthesized operator on a pointer, use the pointer's PointedAtType.
                    if (symbol.IsKind(SymbolKind.Method) &&
                        ((IMethodSymbol)symbol).MethodKind == MethodKind.BuiltinOperator &&
                        symbol.ContainingSymbol.IsKind(SymbolKind.PointerType))
                    {
                        return IsSymbolAccessibleCore(((IPointerTypeSymbol)symbol.ContainingSymbol).PointedAtType, within, null, out failedThroughTypeCheck);
                    }

                    return IsMemberAccessible(symbol.ContainingType, symbol.DeclaredAccessibility, within, throughTypeOpt, out failedThroughTypeCheck);

                default:
                    throw ExceptionUtilities.Unreachable;
            }
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:86,代码来源:ISymbolExtensions_Accessibility.cs

示例2: HidingTypeParameterSymbolExists

        /// <summary>
        /// Returns True if enclosingTypeParametersInsideOut contains a symbol with the same name as the candidateSymbol
        /// thereby saying that there exists a symbol which hides the candidate Symbol
        /// </summary>
        private static bool HidingTypeParameterSymbolExists(ISymbol candidateSymbol, List<ISymbol> enclosingTypeParametersInsideOut)
        {
            foreach (var enclosingTypeParameter in enclosingTypeParametersInsideOut)
            {
                ISymbol newCandidateSymbol = candidateSymbol;
                if (candidateSymbol.IsKind(SymbolKind.ArrayType))
                {
                    newCandidateSymbol = ((IArrayTypeSymbol)candidateSymbol).ElementType;
                }

                if (newCandidateSymbol.MetadataName == enclosingTypeParameter.MetadataName)
                {
                    if (SymbolEquivalenceComparer.Instance.Equals(newCandidateSymbol.GetOriginalUnreducedDefinition(), enclosingTypeParameter.GetOriginalUnreducedDefinition()))
                    {
                        return false;
                    }

                    return true;
                }
            }

            return false;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:27,代码来源:ExpressionSyntaxExtensions.cs

示例3: CheckXmlDocForErrors

            void CheckXmlDocForErrors(SyntaxNode node, ISymbol member)
            {
                context.CancellationToken.ThrowIfCancellationRequested();

                foreach (var triva in node.GetLeadingTrivia())
                {
                    if (triva.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia))
                    {
                        storedXmlComment.Add((DocumentationCommentTriviaSyntax)triva.GetStructure());
                        new CRefVisistor(this).Visit(triva.GetStructure ());
                    }
                }

                if (storedXmlComment.Count == 0)
                    return;

                xml.Clear();
                xml.Append(firstline);
                var OffsetTable = new List<int>();
                foreach (var cmt in storedXmlComment)
                {
                    OffsetTable.Add(xml.Length - firstline.Length);
                    xml.Append(cmt.Content + "\n");
                }
                xml.Append("</root>\n");

                var doc = new AXmlParser().Parse(SourceText.From(xml.ToString()));

                var stack = new Stack<AXmlObject>();
                stack.Push(doc);
                foreach (var err in doc.SyntaxErrors)
                {
                    AddXmlIssue(CalculateRealStartOffset(OffsetTable, err.StartOffset), err.EndOffset - err.StartOffset, err.Description);
                }

                while (stack.Count > 0) {
                    var cur = stack.Pop();
                    var el = cur as AXmlElement;
                    if (el != null) {
                        switch (el.Name)
                        {
                            case "typeparam":
                            case "typeparamref":
                                var name = el.Attributes.FirstOrDefault(attr => attr.Name == "name");
                                if (name == null || name.ValueSegment.Length < 2)
                                    break;
                                if (member != null && member.IsKind(SymbolKind.NamedType))
                                {
                                    var type = (INamedTypeSymbol)member;
                                    if (!type.TypeArguments.Any(arg => arg.Name == name.Value))
                                    {
                                        AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Type parameter '{0}' not found"), name.Value));
                                    }
                                }
                                break;
                            case "param":
                            case "paramref":
                                name = el.Attributes.FirstOrDefault(attr => attr.Name == "name");
                                if (name == null || name.ValueSegment.Length < 2)
                                    break;
                                var m = member as IMethodSymbol;
                                if (m != null)
                                {
                                    if (m.Parameters.Any(p => p.Name == name.Value))
                                        break;
                                    AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
                                    break;
                                }
                                var prop = member as IPropertySymbol;
                                if (prop != null)
                                {
                                    if (prop.Parameters.Any(p => p.Name == name.Value))
                                        break;
                                    if (name.Value == "value")
                                        break;
                                    AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
                                    break;
                                }
                                var evt = member as IEventSymbol;
                                if (evt != null)
                                {
                                    if (name.Value == "value")
                                        break;
                                    AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
                                    break;
                                }
                                var named = member as INamedTypeSymbol;
                                if (named != null)
                                {
                                    if (named.DelegateInvokeMethod == null)
                                        break;
                                    if (named.DelegateInvokeMethod.Parameters.Any(p => p.Name == name.Value))
                                        break;
                                    AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
                                    break;
                                }
                                AddXmlIssue(CalculateRealStartOffset(OffsetTable, name.ValueSegment.Start + 1), name.ValueSegment.Length - 2, string.Format(GettextCatalog.GetString("Parameter '{0}' not found"), name.Value));
                                break;
                        }
                    }
//.........这里部分代码省略.........
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:101,代码来源:XmlDocAnalyzer.cs

示例4: AddDeclarationConflictsAsync

        /// <summary>
        /// Computes an adds conflicts relating to declarations, which are independent of
        /// location-based checks. Examples of these types of conflicts include renaming a member to
        /// the same name as another member of a type: binding doesn't change (at least from the
        /// perspective of find all references), but we still need to track it.
        /// </summary>
        internal static async Task AddDeclarationConflictsAsync(
            ISymbol renamedSymbol,
            ISymbol renameSymbol,
            IEnumerable<SymbolAndProjectId> referencedSymbols,
            ConflictResolution conflictResolution,
            IDictionary<Location, Location> reverseMappedLocations,
            CancellationToken cancellationToken)
        {
            if (renamedSymbol.ContainingSymbol.IsKind(SymbolKind.NamedType))
            {
                var otherThingsNamedTheSame = renamedSymbol.ContainingType.GetMembers(renamedSymbol.Name)
                                                       .Where(s => !s.Equals(renamedSymbol) &&
                                                                   string.Equals(s.MetadataName, renamedSymbol.MetadataName, StringComparison.Ordinal) &&
                                                                   (s.Kind != SymbolKind.Method || renamedSymbol.Kind != SymbolKind.Method));

                AddConflictingSymbolLocations(otherThingsNamedTheSame, conflictResolution, reverseMappedLocations);
            }


            if (renamedSymbol.IsKind(SymbolKind.Namespace) && renamedSymbol.ContainingSymbol.IsKind(SymbolKind.Namespace))
            {
                var otherThingsNamedTheSame = ((INamespaceSymbol)renamedSymbol.ContainingSymbol).GetMembers(renamedSymbol.Name)
                                                        .Where(s => !s.Equals(renamedSymbol) &&
                                                                    !s.IsKind(SymbolKind.Namespace) &&
                                                                    string.Equals(s.MetadataName, renamedSymbol.MetadataName, StringComparison.Ordinal));

                AddConflictingSymbolLocations(otherThingsNamedTheSame, conflictResolution, reverseMappedLocations);
            }

            if (renamedSymbol.IsKind(SymbolKind.NamedType) && renamedSymbol.ContainingSymbol is INamespaceOrTypeSymbol)
            {
                var otherThingsNamedTheSame = ((INamespaceOrTypeSymbol)renamedSymbol.ContainingSymbol).GetMembers(renamedSymbol.Name)
                                                        .Where(s => !s.Equals(renamedSymbol) &&
                                                                    string.Equals(s.MetadataName, renamedSymbol.MetadataName, StringComparison.Ordinal));

                var conflictingSymbolLocations = otherThingsNamedTheSame.Where(s => !s.IsKind(SymbolKind.Namespace));
                if (otherThingsNamedTheSame.Any(s => s.IsKind(SymbolKind.Namespace)))
                {
                    conflictingSymbolLocations = conflictingSymbolLocations.Concat(renamedSymbol);
                }

                AddConflictingSymbolLocations(conflictingSymbolLocations, conflictResolution, reverseMappedLocations);
            }

            // Some types of symbols (namespaces, cref stuff, etc) might not have ContainingAssemblies
            if (renamedSymbol.ContainingAssembly != null)
            {
                var project = conflictResolution.NewSolution.GetProject(renamedSymbol.ContainingAssembly, cancellationToken);

                // There also might be language specific rules we need to include
                var languageRenameService = project.LanguageServices.GetService<IRenameRewriterLanguageService>();
                var languageConflicts = await languageRenameService.ComputeDeclarationConflictsAsync(
                    conflictResolution.ReplacementText,
                    renamedSymbol,
                    renameSymbol,
                    referencedSymbols,
                    conflictResolution.OldSolution,
                    conflictResolution.NewSolution,
                    reverseMappedLocations,
                    cancellationToken).ConfigureAwait(false);

                foreach (var languageConflict in languageConflicts)
                {
                    conflictResolution.AddOrReplaceRelatedLocation(new RelatedLocation(languageConflict.SourceSpan, conflictResolution.OldSolution.GetDocument(languageConflict.SourceTree).Id, RelatedLocationType.UnresolvableConflict));
                }
            }
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:73,代码来源:ConflictResolver.cs

示例5: AppliesTo

 public bool AppliesTo(ISymbol symbol)
 {
     if (SymbolKind.HasValue)
     {
         return symbol.IsKind(SymbolKind.Value);
     }
     else
     {
         var typeSymbol = symbol as ITypeSymbol;
         return typeSymbol != null && typeSymbol.TypeKind == TypeKind.Value;
     }
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:12,代码来源:SymbolSpecification.cs

示例6: IsApplicable

        /// <summary>
        /// Is this method or property a valid place to set a breakpoint and does it match the expected parameter count?
        /// </summary>
        private bool IsApplicable(ISymbol methodOrProperty, int? parameterCount, CancellationToken cancellationToken)
        {
            // You can only set a breakpoint on methods (including constructors/destructors) and properties.
            var kind = methodOrProperty.Kind;
            if (!(kind == SymbolKind.Method || kind == SymbolKind.Property))
            {
                return false;
            }

            // You can't set a breakpoint on an abstract method or property.
            if (methodOrProperty.IsAbstract)
            {
                return false;
            }

            // If parameters were provided, check to make sure the method or property has the expected number
            // of parameters (but we don't actually validate the type or name of the supplied parameters).
            if (parameterCount != null)
            {
                var mismatch = IsMismatch(methodOrProperty, parameterCount);

                if (mismatch)
                {
                    return false;
                }
            }

            // Finally, check to make sure we have source, and if we've got a method symbol, make sure it
            // has a body to set a breakpoint on.
            if ((methodOrProperty.Language == _language) && methodOrProperty.Locations.Any(location => location.IsInSource))
            {
                if (methodOrProperty.IsKind(SymbolKind.Method))
                {
                    return HasMethodBody((IMethodSymbol)methodOrProperty, cancellationToken);
                }

                // Non-abstract properties are always applicable, because you can set a breakpoint on the
                // accessor methods (get and/or set).
                return true;
            }

            return false;
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:46,代码来源:AbstractBreakpointResolver.cs

示例7: CheckParameters

        static void CheckParameters(SyntaxNodeAnalysisContext ctx, ISymbol member, List<ISymbol> overloads, SeparatedSyntaxList<ParameterSyntax> parameterListNodes)
        {
            var memberParameters = member.GetParameters();
            for (int i = 0; i < memberParameters.Length; i++)
            {
                if (!memberParameters[i].IsOptional)
                    continue;

                foreach (var overload in overloads)
                {
                    if (overload.GetParameters().Length != i)
                        continue;
                    bool equal = true;
                    for (int j = 0; j < i; j++)
                    {
                        if (overload.GetParameters()[j].Type != memberParameters[j].Type)
                        {
                            equal = false;
                            break;
                        }
                    }
                    if (equal)
                    {
                        ctx.ReportDiagnostic( Diagnostic.Create(
                            descriptor,
                            parameterListNodes[i].GetLocation(),
                            member.IsKind(SymbolKind.Method) ? GettextCatalog.GetString("Method") : GettextCatalog.GetString("Indexer")
                        ));
                    }
                }
            }
        }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:32,代码来源:MethodOverloadWithOptionalParameterAnalyzer.cs


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