本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol.InterfacesNoUseSiteDiagnostics方法的典型用法代码示例。如果您正苦于以下问题:C# NamedTypeSymbol.InterfacesNoUseSiteDiagnostics方法的具体用法?C# NamedTypeSymbol.InterfacesNoUseSiteDiagnostics怎么用?C# NamedTypeSymbol.InterfacesNoUseSiteDiagnostics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol
的用法示例。
在下文中一共展示了NamedTypeSymbol.InterfacesNoUseSiteDiagnostics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasDuplicateInterfaces
// C# does not let you declare a type in which it would be possible for distinct base interfaces
// to unify under some instantiations. But such ill-formed classes can come in through
// metadata and be instantiated in C#. We check to see if that's happened.
private static bool HasDuplicateInterfaces(NamedTypeSymbol type, ConsList<Symbol> basesBeingResolved)
{
// PERF: avoid instantiating all interfaces here
// Ex: if class implements just IEnumerable<> and IComparable<> it cannot have conflicting implementations
var array = type.OriginalDefinition.InterfacesNoUseSiteDiagnostics(basesBeingResolved);
switch (array.Length)
{
case 0:
case 1:
// less than 2 interfaces
return false;
case 2:
if ((object)array[0].OriginalDefinition == array[1].OriginalDefinition)
{
break;
}
// two unrelated interfaces
return false;
default:
var set = PooledHashSet<object>.GetInstance();
foreach (var i in array)
{
if (!set.Add(i.OriginalDefinition))
{
set.Free();
goto hasRelatedInterfaces;
}
}
// all interfaces are unrelated
set.Free();
return false;
}
// very rare case.
// some implemented interfaces are related
// will have to instantiate interfaces and check
hasRelatedInterfaces:
return type.InterfacesNoUseSiteDiagnostics(basesBeingResolved).HasDuplicates(TypeSymbol.EqualsIgnoringDynamicAndTupleNamesComparer);
}
示例2: CheckBaseTypeCompliance
private void CheckBaseTypeCompliance(NamedTypeSymbol symbol)
{
System.Diagnostics.Debug.Assert(IsTrue(GetDeclaredOrInheritedCompliance(symbol)), "Only call on compliant symbols");
// NOTE: implemented interfaces do not have to be CLS-compliant (unless the type itself is an interface).
if (symbol.IsInterface)
{
foreach (NamedTypeSymbol interfaceType in symbol.InterfacesNoUseSiteDiagnostics())
{
if (!IsCompliantType(interfaceType, symbol))
{
// TODO: it would be nice to report this on the base type clause.
this.AddDiagnostic(ErrorCode.WRN_CLS_BadInterface, symbol.Locations[0], symbol, interfaceType);
}
}
}
else
{
NamedTypeSymbol baseType = symbol.EnumUnderlyingType ?? symbol.BaseTypeNoUseSiteDiagnostics; // null for interfaces
System.Diagnostics.Debug.Assert((object)baseType != null || symbol.SpecialType == SpecialType.System_Object, "Only object has no base.");
if ((object)baseType != null && !IsCompliantType(baseType, symbol))
{
// TODO: it would be nice to report this on the base type clause.
this.AddDiagnostic(ErrorCode.WRN_CLS_BadBase, symbol.Locations[0], symbol, baseType);
}
}
}
示例3: InterfacesAreDistinct
// C# does not let you declare a type in which it would be possible for distinct base interfaces
// to unify under some instantiations. But such ill-formed classes can come in through
// metadata and be instantiated in C#. We check to see if that's happened.
private static bool InterfacesAreDistinct(NamedTypeSymbol type, ConsList<Symbol> basesBeingResolved)
{
return !type.InterfacesNoUseSiteDiagnostics(basesBeingResolved).HasDuplicates(TypeSymbol.EqualsIgnoringDynamicComparer);
}
示例4: InterfacesVisit
/// <summary>
/// Add the type to the builder and then recurse on its interfaces.
/// </summary>
/// <remarks>
/// Pre-order depth-first search.
/// </remarks>
private static void InterfacesVisit(NamedTypeSymbol namedType, ArrayBuilder<NamedTypeSymbol> builder, ref HashSet<NamedTypeSymbol> seen)
{
// It's not clear how important the order of these interfaces is, but Dev10
// maintains pre-order depth-first/declaration order, so we probably should as well.
// That's why we're not using InterfacesAndTheirBaseInterfaces - it's an unordered set.
foreach (NamedTypeSymbol @interface in namedType.InterfacesNoUseSiteDiagnostics())
{
if (seen == null)
{
// Don't allocate until we see at least one interface.
seen = new HashSet<NamedTypeSymbol>();
}
if (seen.Add(@interface))
{
builder.Add(@interface);
InterfacesVisit(@interface, builder, ref seen);
}
}
}