本文整理汇总了C#中TypeSymbol.IsInterfaceType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.IsInterfaceType方法的具体用法?C# TypeSymbol.IsInterfaceType怎么用?C# TypeSymbol.IsInterfaceType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.IsInterfaceType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsVarianceCast
// Although III.1.8.1.3 seems to imply that verifier understands variance casts.
// It appears that verifier/JIT gets easily confused.
// So to not rely on whether that should work or not we will flag potentially
// "complicated" casts and make them static casts to ensure we are all on
// the same page with what type should be tracked.
private static bool IsVarianceCast(TypeSymbol to, TypeSymbol from)
{
if (to == from)
{
return false;
}
if ((object)from == null)
{
// from unknown type - this could be a variance conversion.
return true;
}
// while technically variance casts, array conversions do not seem to be a problem
// unless the element types are converted via variance.
if (to.IsArray())
{
return IsVarianceCast(((ArrayTypeSymbol)to).ElementType, ((ArrayTypeSymbol)from).ElementType);
}
return (to.IsDelegateType() && to != from) ||
(to.IsInterfaceType() && from.IsInterfaceType() && !from.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics.Contains((NamedTypeSymbol)to));
}
示例2: AddUserDefinedConversionsToExplicitCandidateSet
private void AddUserDefinedConversionsToExplicitCandidateSet(
BoundExpression sourceExpression,
TypeSymbol source,
TypeSymbol target,
ArrayBuilder<UserDefinedConversionAnalysis> u,
NamedTypeSymbol declaringType,
string operatorName,
ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert(sourceExpression != null || (object)source != null);
Debug.Assert((object)target != null);
Debug.Assert(u != null);
Debug.Assert((object)declaringType != null);
Debug.Assert(operatorName != null);
// SPEC: Find the set of applicable user-defined and lifted conversion operators, U.
// SPEC: The set consists of the user-defined and lifted implicit or explicit
// SPEC: conversion operators declared by the classes and structs in D that convert
// SPEC: from a type encompassing E or encompassed by S (if it exists) to a type
// SPEC: encompassing or encompassed by T.
// DELIBERATE SPEC VIOLATION:
//
// The spec here essentially says that we add an applicable "regular" conversion and
// an applicable lifted conversion, if there is one, to the candidate set, and then
// let them duke it out to determine which one is "best".
//
// This is not at all what the native compiler does, and attempting to implement
// the specification, or slight variations on it, produces too many backwards-compatibility
// breaking changes.
//
// The native compiler deviates from the specification in two major ways here.
// First, it does not add *both* the regular and lifted forms to the candidate set.
// Second, the way it characterizes a "lifted" form is very, very different from
// how the specification characterizes a lifted form.
//
// An operation, in this case, X-->Y, is properly said to be "lifted" to X?-->Y? via
// the rule that X?-->Y? matches the behavior of X-->Y for non-null X, and converts
// null X to null Y otherwise.
//
// The native compiler, by contrast, takes the existing operator and "lifts" either
// the operator's parameter type or the operator's return type to nullable. For
// example, a conversion from X?-->Y would be "lifted" to X?-->Y? by making the
// conversion from X? to Y, and then from Y to Y?. No "lifting" semantics
// are imposed; we do not check to see if the X? is null. This operator is not
// actually "lifted" at all; rather, an implicit conversion is applied to the
// output. **The native compiler considers the result type Y? of that standard implicit
// conversion to be the result type of the "lifted" conversion**, rather than
// properly considering Y to be the result type of the conversion for the purposes
// of computing the best output type.
//
// Moreover: the native compiler actually *does* implement nullable lifting semantics
// in the case where the input type of the user-defined conversion is a non-nullable
// value type and the output type is a nullable value type **or pointer type, or
// reference type**. This is an enormous departure from the specification; the
// native compiler will take a user-defined conversion from X-->Y? or X-->C and "lift"
// it to a conversion from X?-->Y? or X?-->C that has nullable semantics.
//
// This is quite confusing. In this code we will classify the conversion as either
// "normal" or "lifted" on the basis of *whether or not special lifting semantics
// are to be applied*. That is, whether or not a later rewriting pass is going to
// need to insert a check to see if the source expression is null, and decide
// whether or not to call the underlying unlifted conversion or produce a null
// value without calling the unlifted conversion.
// DELIBERATE SPEC VIOLATION: See the comment regarding bug 17021 in
// UserDefinedImplicitConversions.cs.
if ((object)source != null && source.IsInterfaceType() || target.IsInterfaceType())
{
return;
}
foreach (MethodSymbol op in declaringType.GetOperators(operatorName))
{
// We might have a bad operator and be in an error recovery situation. Ignore it.
if (op.ReturnsVoid || op.ParameterCount != 1 || op.ReturnType.TypeKind == TypeKind.Error)
{
continue;
}
TypeSymbol convertsFrom = op.ParameterTypes[0];
TypeSymbol convertsTo = op.ReturnType;
Conversion fromConversion = EncompassingExplicitConversion(sourceExpression, source, convertsFrom, ref useSiteDiagnostics);
Conversion toConversion = EncompassingExplicitConversion(null, convertsTo, target, ref useSiteDiagnostics);
// We accept candidates for which the parameter type encompasses the *underlying* source type.
if (!fromConversion.Exists &&
(object)source != null &&
source.IsNullableType() &&
EncompassingExplicitConversion(null, source.GetNullableUnderlyingType(), convertsFrom, ref useSiteDiagnostics).Exists)
{
fromConversion = ClassifyConversion(source, convertsFrom, ref useSiteDiagnostics, builtinOnly: true);
}
// As in dev11 (and the revised spec), we also accept candidates for which the return type is encompassed by the *stripped* target type.
if (!toConversion.Exists &&
(object)target != null &&
target.IsNullableType() &&
EncompassingExplicitConversion(null, convertsTo, target.GetNullableUnderlyingType(), ref useSiteDiagnostics).Exists)
{
//.........这里部分代码省略.........