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


C# INamedTypeSymbol.FindImplementationForInterfaceMember方法代码示例

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


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

示例1: ContainingTypeImplementsIDisposableAndCallsItOnTheField

 private static bool ContainingTypeImplementsIDisposableAndCallsItOnTheField(SymbolAnalysisContext context, IFieldSymbol fieldSymbol, INamedTypeSymbol typeSymbol)
 {
     if (typeSymbol == null) return false;
     var iDisposableInterface = typeSymbol.AllInterfaces.FirstOrDefault(i => i.ToString() == "System.IDisposable");
     if (iDisposableInterface != null)
     {
         var disposableMethod = iDisposableInterface.GetMembers("Dispose").OfType<IMethodSymbol>().First(d => d.Arity == 0);
         var disposeMethodSymbol = typeSymbol.FindImplementationForInterfaceMember(disposableMethod) as IMethodSymbol;
         if (disposeMethodSymbol != null)
         {
             var disposeMethod = (MethodDeclarationSyntax)disposeMethodSymbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax();
             if (disposeMethod == null) return false;
             if (disposeMethod.Modifiers.Any(SyntaxKind.AbstractKeyword)) return true;
             var typeDeclaration = (TypeDeclarationSyntax)typeSymbol.DeclaringSyntaxReferences.FirstOrDefault().GetSyntax();
             var semanticModel = context.Compilation.GetSemanticModel(typeDeclaration.SyntaxTree);
             if (CallsDisposeOnField(fieldSymbol, disposeMethod, semanticModel)) return true;
         }
     }
     return false;
 }
开发者ID:Cadums01,项目名称:code-cracker,代码行数:20,代码来源:DisposableFieldNotDisposedAnalyzer.cs

示例2: GetImplementingInterface

 static INamedTypeSymbol GetImplementingInterface(ISymbol enclosingSymbol, INamedTypeSymbol containingType)
 {
     INamedTypeSymbol result = null;
     foreach (var iface in containingType.AllInterfaces)
     {
         foreach (var member in iface.GetMembers())
         {
             var implementation = containingType.FindImplementationForInterfaceMember(member);
             if (implementation == enclosingSymbol)
             {
                 if (result != null)
                     return null;
                 result = iface;
             }
         }
     }
     return result;
 }
开发者ID:yeaicc,项目名称:RefactoringEssentials,代码行数:18,代码来源:UnusedParameterAnalyzer.cs

示例3: HasInterfaceMember

 private static bool HasInterfaceMember(INamedTypeSymbol classSymbol, INamedTypeSymbol interfaceType)
 {
     return interfaceType.GetMembers().Any(interfaceMember =>
     {
         var classMember = classSymbol.FindImplementationForInterfaceMember(interfaceMember);
         return classMember != null &&
             classMember.ContainingType.Equals(classSymbol);
     });
 }
开发者ID:Thejas007,项目名称:sonarlint-vs,代码行数:9,代码来源:RedundantInheritanceList.cs

示例4: IsInterfacePropertyImplemented

        private static bool IsInterfacePropertyImplemented(INamedTypeSymbol classOrStructType, IPropertySymbol propertySymbol, CancellationToken cancellationToken)
        {
            // A property is only fully implemented if both it's setter and getter is implemented.
            if (propertySymbol.GetMethod != null)
            {
                if (classOrStructType.FindImplementationForInterfaceMember(propertySymbol.GetMethod) == null)
                {
                    return false;
                }
            }

            if (propertySymbol.SetMethod != null)
            {
                if (classOrStructType.FindImplementationForInterfaceMember(propertySymbol.SetMethod) == null)
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:21,代码来源:INamedTypeSymbolExtensions.cs

示例5: ImplementationExists

 private static bool ImplementationExists(INamedTypeSymbol classOrStructType, ISymbol member)
 {
     return classOrStructType.FindImplementationForInterfaceMember(member) != null;
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:4,代码来源:INamedTypeSymbolExtensions.cs

示例6: FindDisposeMethod

            /// <summary>
            /// Returns method that implements IDisposable.Dispose operation.
            /// Only direct implementation is taken into account, implementation in base type is ignored.
            /// </summary>
            private IMethodSymbol FindDisposeMethod(INamedTypeSymbol type)
            {
                var disposeMethod = type.FindImplementationForInterfaceMember(_disposeInterfaceMethod) as IMethodSymbol;
                if (disposeMethod != null && disposeMethod.ContainingType == type)
                {
                    return disposeMethod;
                }

                return null;
            }
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:14,代码来源:ImplementIDisposableCorrectly.cs

示例7: CanInterfacebeRemovedbasedOnMembers

        private static bool CanInterfacebeRemovedbasedOnMembers(INamedTypeSymbol declaredType, INamedTypeSymbol interfaceType)
        {
            var allMembersOfInterface = interfaceType.AllInterfaces.Concat(new[] { interfaceType })
                .SelectMany(i => i.GetMembers())
                .ToList();

            if (!allMembersOfInterface.Any())
            {
                return false;
            }

            foreach (var interfaceMember in allMembersOfInterface)
            {
                var classMember = declaredType.FindImplementationForInterfaceMember(interfaceMember);
                if (classMember != null &&
                    (classMember.ContainingType.Equals(declaredType) ||
                    !classMember.ContainingType.Interfaces.SelectMany(i => i.AllInterfaces.Concat(new[] { i })).Contains(interfaceType)))
                {
                    return false;
                }
            }
            return true;
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:23,代码来源:RedundantInheritanceList.cs


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