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


C# ISymbol.ExplicitInterfaceImplementations方法代码示例

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


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

示例1: HasConflict

            private bool HasConflict(ISymbol member1, ISymbol member2)
            {
                // If either of these members are invisible explicit, then there is no conflict.
                if (Service.HasHiddenExplicitImplementation)
                {
                    if (member1.ExplicitInterfaceImplementations().Any() || member2.ExplicitInterfaceImplementations().Any())
                    {
                        // explicit methods don't conflict with anything.
                        return false;
                    }
                }

                // Members normally conflict if they have the same name.  The exceptions are methods
                // and parameterized properties (which conflict if htey have the same signature).
                if (!IdentifiersMatch(member1.Name, member2.Name))
                {
                    return false;
                }

                // If they differ in type, then it's almost always a conflict.  There may be
                // exceptions to this, but i don't know of any.
                if (member1.Kind != member2.Kind)
                {
                    return true;
                }

                // At this point, we have two members of the same type with the same name.  If they
                // have a different signature (for example, methods, or parameterized properties),
                // then they do not conflict.
                if (!SignatureComparer.HaveSameSignature(member1, member2, this.IsCaseSensitive))
                {
                    return false;
                }

                // Now we have to members with the same name, type and signature. If the language
                // doesn't support implicit implementation, then these members are definitely in
                // conflict.
                if (!Service.CanImplementImplicitly)
                {
                    return true;
                }

                // two members conflict if they have the same signature and have
                //
                // a) different return types
                // b) different accessibility
                // c) different constraints
                if (member1.DeclaredAccessibility != member2.DeclaredAccessibility ||
                    !SignatureComparer.HaveSameSignatureAndConstraintsAndReturnTypeAndAccessors(member1, member2, this.IsCaseSensitive))
                {
                    return true;
                }

                // Same name, type, accessibility, return type, *and* the services can implement
                // implicitly.  These are not in conflict.
                return false;
            }
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:57,代码来源:AbstractImplementInterfaceService.CodeAction_Conflicts.cs

示例2: ShouldIncludeSymbolAsync

            private static async Task<bool> ShouldIncludeSymbolAsync(
                ISymbol referencedSymbol, ISymbol originalSymbol, Solution solution, bool considerSymbolReferences, CancellationToken cancellationToken)
            {
                if (referencedSymbol.IsPropertyAccessor())
                {
                    return considerSymbolReferences;
                }

                if (referencedSymbol.Equals(originalSymbol))
                {
                    return true;
                }

                // Parameters of properties and methods can cascade to each other in
                // indexer scenarios.
                if (originalSymbol.Kind == SymbolKind.Parameter && referencedSymbol.Kind == SymbolKind.Parameter)
                {
                    return true;
                }

                // If the original symbol is a property, cascade to the backing field
                if (referencedSymbol.Kind == SymbolKind.Field && originalSymbol.Equals(((IFieldSymbol)referencedSymbol).AssociatedSymbol))
                {
                    return true;
                }

                // If the symbol doesn't actually exist in source, we never want to rename it
                if (referencedSymbol.IsImplicitlyDeclared)
                {
                    return considerSymbolReferences;
                }

                // We can cascade from members to other members only if the names match. The example
                // where the names might be different is explicit interface implementations in
                // Visual Basic and VB's identifiers are case insensitive. 
                // Do not cascade to symbols that are defined only in metadata.
                if (referencedSymbol.Kind == originalSymbol.Kind &&
                    string.Compare(TrimNameToAfterLastDot(referencedSymbol.Name), TrimNameToAfterLastDot(originalSymbol.Name), StringComparison.OrdinalIgnoreCase) == 0 &&
                    referencedSymbol.Locations.Any(loc => loc.IsInSource))
                {
                    return true;
                }

                // If the original symbol is an alias, then the referenced symbol will be where we
                // actually see references.
                if (originalSymbol.Kind == SymbolKind.Alias)
                {
                    var target = ((IAliasSymbol)originalSymbol).Target;

                    return target.TypeSwitch(
                        (INamedTypeSymbol nt) => nt.ConstructedFrom.Equals(referencedSymbol),
                        (INamespaceOrTypeSymbol s) => s.Equals(referencedSymbol));
                }

                // cascade from property accessor to property (someone in C# renames base.get_X, or the accessor override)
                if (await IsPropertyAccessorOrAnOverride(referencedSymbol, solution, cancellationToken).ConfigureAwait(false) ||
                    await IsPropertyAccessorOrAnOverride(originalSymbol, solution, cancellationToken).ConfigureAwait(false))
                {
                    return true;
                }

                if (referencedSymbol.ContainingSymbol != null &&
                    referencedSymbol.ContainingSymbol.Kind == SymbolKind.NamedType &&
                    ((INamedTypeSymbol)referencedSymbol.ContainingSymbol).TypeKind == TypeKind.Interface &&
                    !originalSymbol.ExplicitInterfaceImplementations().Any(s => s.Equals(referencedSymbol)))
                {
                    return true;
                }

                return false;
            }
开发者ID:tralivali1234,项目名称:roslyn,代码行数:71,代码来源:RenameLocation.ReferenceProcessing.cs

示例3: MembersMatch

            private bool MembersMatch(ISymbol member1, ISymbol member2)
            {
                if (member1.Kind != member2.Kind)
                {
                    return false;
                }

                if (member1.DeclaredAccessibility != member2.DeclaredAccessibility ||
                    member1.IsStatic != member2.IsStatic)
                {
                    return false;
                }

                if (member1.ExplicitInterfaceImplementations().Any() || member2.ExplicitInterfaceImplementations().Any())
                {
                    return false;
                }

                return SignatureComparer.Instance.HaveSameSignatureAndConstraintsAndReturnTypeAndAccessors(
                    member1, member2, this.IsCaseSensitive);
            }
开发者ID:noahfalk,项目名称:roslyn,代码行数:21,代码来源:AbstractImplementInterfaceService.CodeAction.cs

示例4: AddNodeForSymbolAsync

        public async Task<GraphNode> AddNodeForSymbolAsync(ISymbol symbol, Project contextProject, Document contextDocument)
        {
            // Figure out what the location for this node should be. We'll arbitrarily pick the
            // first one, unless we have a contextDocument to restrict it
            var preferredLocation = symbol.Locations.FirstOrDefault(l => l.SourceTree != null);

            if (contextDocument != null)
            {
                var syntaxTree = await contextDocument.GetSyntaxTreeAsync(_cancellationToken).ConfigureAwait(false);

                // If we have one in that tree, use it
                preferredLocation = symbol.Locations.FirstOrDefault(l => l.SourceTree == syntaxTree) ?? preferredLocation;
            }

            // We may need to look up source code within this solution
            if (preferredLocation == null && symbol.Locations.Any(loc => loc.IsInMetadata))
            {
                var newSymbol = await SymbolFinder.FindSourceDefinitionAsync(symbol, contextProject.Solution, _cancellationToken).ConfigureAwait(false);
                if (newSymbol != null)
                {
                    preferredLocation = newSymbol.Locations.Where(loc => loc.IsInSource).FirstOrDefault();
                }
            }

            using (_gate.DisposableWait())
            {
                GraphNode node = await GetOrCreateNodeAsync(_graph, symbol, _solution, _cancellationToken).ConfigureAwait(false);

                node[RoslynGraphProperties.SymbolId] = (SymbolKey?)symbol.GetSymbolKey();
                node[RoslynGraphProperties.ContextProjectId] = GetContextProjectId(contextProject, symbol);
                node[RoslynGraphProperties.ExplicitInterfaceImplementations] = symbol.ExplicitInterfaceImplementations().Select(s => s.GetSymbolKey()).ToList();
                node[RoslynGraphProperties.DeclaredAccessibility] = symbol.DeclaredAccessibility;
                node[RoslynGraphProperties.SymbolModifiers] = symbol.GetSymbolModifiers();
                node[RoslynGraphProperties.SymbolKind] = symbol.Kind;

                if (contextDocument != null)
                {
                    node[RoslynGraphProperties.ContextDocumentId] = contextDocument.Id;
                }

                if (preferredLocation != null)
                {
                    var lineSpan = preferredLocation.GetLineSpan();
                    var sourceLocation = new SourceLocation(
                        preferredLocation.SourceTree.FilePath,
                        new Position(lineSpan.StartLinePosition.Line, lineSpan.StartLinePosition.Character),
                        new Position(lineSpan.EndLinePosition.Line, lineSpan.EndLinePosition.Character));
                    node[CodeNodeProperties.SourceLocation] = sourceLocation;
                }

                // Keep track of this as a node we have added. Note this is a HashSet, so if the node was already added
                // we won't double-count.
                _createdNodes.Add(node);

                _nodeToSymbolMap[node] = symbol;
                _nodeToContextProjectMap[node] = contextProject;
                _nodeToContextDocumentMap[node] = contextDocument;

                return node;
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:61,代码来源:GraphBuilder.cs

示例5: FindImplementedInterfaceMembersAsync

        /// <summary>
        /// Find symbols for declarations that implement members of the specified interface symbol
        /// </summary>
        public static async Task<IEnumerable<ISymbol>> FindImplementedInterfaceMembersAsync(
            ISymbol symbol, Solution solution, IImmutableSet<Project> projects = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Member can only implement interface members if it is an explicit member, or if it is
            // public and non static.
            if (symbol != null)
            {
                var explicitImplementations = symbol.ExplicitInterfaceImplementations();
                if (explicitImplementations.Length > 0)
                {
                    return explicitImplementations;
                }
                else if (
                    symbol.DeclaredAccessibility == Accessibility.Public && !symbol.IsStatic &&
                    (symbol.ContainingType.TypeKind == TypeKind.Class || symbol.ContainingType.TypeKind == TypeKind.Struct))
                {
                    // Interface implementation is a tricky thing.  A method may implement an interface
                    // method, even if its containing type doesn't state that it implements the
                    // interface.  For example:
                    //
                    //  interface IFoo { void Foo(); }
                    //
                    //  class Base { public void Foo(); }
                    //
                    //  class Derived : Base, IFoo { }
                    //
                    // In this case, Base.Foo *does* implement IFoo.Foo in the context of the type
                    // Derived.
                    var containingType = symbol.ContainingType.OriginalDefinition;
                    var derivedClasses = await SymbolFinder.FindDerivedClassesAsync(containingType, solution, projects, cancellationToken).ConfigureAwait(false);
                    var allTypes = derivedClasses.Concat(containingType);

                    List<ISymbol> results = null;

                    foreach (var type in allTypes)
                    {
                        foreach (var interfaceType in type.AllInterfaces)
                        {
                            if (interfaceType.MemberNames.Contains(symbol.Name))
                            {
                                foreach (var m in interfaceType.GetMembers(symbol.Name))
                                {
                                    var interfaceMethod = await FindSourceDefinitionAsync(m, solution, cancellationToken).ConfigureAwait(false) ?? m;

                                    foreach (var implementation in type.FindImplementationsForInterfaceMember(interfaceMethod, solution.Workspace, cancellationToken))
                                    {
                                        if (implementation != null && SymbolEquivalenceComparer.Instance.Equals(implementation.OriginalDefinition, symbol.OriginalDefinition))
                                        {
                                            results = results ?? new List<ISymbol>();
                                            results.Add(interfaceMethod);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (results != null)
                    {
                        return results.Distinct(SymbolEquivalenceComparer.Instance);
                    }
                }
            }

            return SpecializedCollections.EmptyEnumerable<ISymbol>();
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:69,代码来源:SymbolFinder_Hierarchy.cs

示例6: ShouldRenameOnlyAffectDeclaringProject

 /// <summary>
 /// Renaming a private symbol typically confines the set of references and potential
 /// conflicts to that symbols declaring project. However, rename may cascade to
 /// non-public symbols which may then require other projects be considered.
 /// </summary>
 private static bool ShouldRenameOnlyAffectDeclaringProject(ISymbol symbol)
 {
     // Explicit interface implementations can cascade to other projects
     return symbol.DeclaredAccessibility == Accessibility.Private && !symbol.ExplicitInterfaceImplementations().Any();
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:10,代码来源:RenameUtilities.cs

示例7: IsExtractableMember

 internal override bool IsExtractableMember(ISymbol m)
 {
     return base.IsExtractableMember(m) && !m.ExplicitInterfaceImplementations().Any();
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:4,代码来源:CSharpExtractInterfaceService.cs


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