本文整理汇总了C#中TypeSymbol.AllInterfacesWithDefinitionUseSiteDiagnostics方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.AllInterfacesWithDefinitionUseSiteDiagnostics方法的具体用法?C# TypeSymbol.AllInterfacesWithDefinitionUseSiteDiagnostics怎么用?C# TypeSymbol.AllInterfacesWithDefinitionUseSiteDiagnostics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.AllInterfacesWithDefinitionUseSiteDiagnostics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpperBoundInterfaceInference
private bool UpperBoundInterfaceInference(NamedTypeSymbol source, TypeSymbol target, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert((object)source != null);
Debug.Assert((object)target != null);
if (!source.IsInterface)
{
return false;
}
// SPEC: * Otherwise, if U [source] is an interface type C<U1...Uk> and V [target] is a class type
// SPEC: or struct type and there is a unique set V1...Vk such that V directly
// SPEC: or indirectly implements C<V1...Vk> then an exact ...
// SPEC: * ... and U is an interface type ...
switch (target.TypeKind)
{
case TypeKind.Struct:
case TypeKind.Class:
case TypeKind.Interface:
break;
default:
return false;
}
NamedTypeSymbol bestInterface = GetInterfaceInferenceBound(target.AllInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics), source);
if ((object)bestInterface == null)
{
return false;
}
UpperBoundTypeArgumentInference(source, bestInterface, ref useSiteDiagnostics);
return true;
}
示例2: HasUniqueInterface
private static bool HasUniqueInterface(TypeSymbol instanceType, NamedTypeSymbol interfaceType, ref bool nonUnique, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
TypeSymbol candidate = null;
foreach (var i in instanceType.AllInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics))
{
if (i.OriginalDefinition == interfaceType)
{
if ((object)candidate == null)
{
candidate = i;
}
else if (candidate != i)
{
nonUnique = true;
return false; // not unique
}
}
}
return (object)candidate != null;
}
示例3: LowerBoundInterfaceInference
private bool LowerBoundInterfaceInference(TypeSymbol source, NamedTypeSymbol target, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert((object)source != null);
Debug.Assert((object)target != null);
if (!target.IsInterface)
{
return false;
}
// Spec 7.5.2.9 Lower-bound interfaces
// SPEC: * Otherwise, if V [target] is an interface type C<V1...Vk> and U [source] is a class type
// SPEC: or struct type and there is a unique set U1...Uk such that U directly
// SPEC: or indirectly implements C<U1...Uk> then an
// SPEC: exact, upper-bound, or lower-bound inference ...
// SPEC: * ... and U is an interface type ...
// SPEC: * ... and U is a type parameter ...
ImmutableArray<NamedTypeSymbol> allInterfaces;
switch (source.TypeKind)
{
case TypeKind.Struct:
case TypeKind.Class:
case TypeKind.Interface:
allInterfaces = source.AllInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics);
break;
case TypeKind.TypeParameter:
var typeParameter = (TypeParameterSymbol)source;
allInterfaces = typeParameter.EffectiveBaseClass(ref useSiteDiagnostics).
AllInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics).
Concat(typeParameter.AllEffectiveInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics));
break;
default:
return false;
}
NamedTypeSymbol matchingInterface = GetInterfaceInferenceBound(allInterfaces, target);
if ((object)matchingInterface == null)
{
return false;
}
LowerBoundTypeArgumentInference(matchingInterface, target, ref useSiteDiagnostics);
return true;
}
示例4: AllInterfacesContainsIEnumerable
/// <summary>
/// Checks if the given type implements (or extends, in the case of an interface),
/// System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>,
/// for at least one T.
/// </summary>
/// <param name="builder">builder to fill in CollectionType.</param>
/// <param name="type">Type to check.</param>
/// <param name="diagnostics" />
/// <param name="foundMultiple">True if multiple T's are found.</param>
/// <returns>True if some IEnumerable is found (may still be ambiguous).</returns>
private bool AllInterfacesContainsIEnumerable(
ref ForEachEnumeratorInfo.Builder builder,
TypeSymbol type,
DiagnosticBag diagnostics,
out bool foundMultiple)
{
Debug.Assert(!IsIEnumerable(type));
NamedTypeSymbol implementedIEnumerable = null;
foundMultiple = false;
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
if (type.TypeKind == TypeKind.TypeParameter)
{
var typeParameter = (TypeParameterSymbol)type;
GetIEnumerableOfT(typeParameter.EffectiveBaseClass(ref useSiteDiagnostics).AllInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics), ref @implementedIEnumerable, ref foundMultiple);
GetIEnumerableOfT(typeParameter.AllEffectiveInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics), ref @implementedIEnumerable, ref foundMultiple);
}
else
{
GetIEnumerableOfT(type.AllInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics), ref @implementedIEnumerable, ref foundMultiple);
}
// Prefer generic to non-generic, unless it is inaccessible.
if (((object)implementedIEnumerable == null) || !this.IsAccessible(implementedIEnumerable, ref useSiteDiagnostics))
{
implementedIEnumerable = null;
var implementedNonGeneric = this.Compilation.GetSpecialType(SpecialType.System_Collections_IEnumerable);
if ((object)implementedNonGeneric != null)
{
var conversion = this.Conversions.ClassifyImplicitConversion(type, implementedNonGeneric, ref useSiteDiagnostics);
if (conversion.IsImplicit)
{
implementedIEnumerable = implementedNonGeneric;
}
}
}
diagnostics.Add(_syntax.Expression, useSiteDiagnostics);
builder.CollectionType = implementedIEnumerable;
return (object)implementedIEnumerable != null;
}