本文整理汇总了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;
}
示例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;
}
示例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);
});
}
示例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;
}
示例5: ImplementationExists
private static bool ImplementationExists(INamedTypeSymbol classOrStructType, ISymbol member)
{
return classOrStructType.FindImplementationForInterfaceMember(member) != null;
}
示例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;
}
示例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;
}