本文整理汇总了C#中Microsoft.CSharp.RuntimeBinder.Semantics.CType.IsArrayType方法的典型用法代码示例。如果您正苦于以下问题:C# CType.IsArrayType方法的具体用法?C# CType.IsArrayType怎么用?C# CType.IsArrayType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.RuntimeBinder.Semantics.CType
的用法示例。
在下文中一共展示了CType.IsArrayType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckAccess2
public virtual ACCESSERROR CheckAccess2(Symbol symCheck, AggregateType atsCheck, Symbol symWhere, CType typeThru)
{
Debug.Assert(symCheck != null);
Debug.Assert(atsCheck == null || symCheck.parent == atsCheck.getAggregate());
Debug.Assert(typeThru == null ||
typeThru.IsAggregateType() ||
typeThru.IsTypeParameterType() ||
typeThru.IsArrayType() ||
typeThru.IsNullableType() ||
typeThru.IsErrorType());
#if DEBUG
switch (symCheck.getKind())
{
default:
break;
case SYMKIND.SK_MethodSymbol:
case SYMKIND.SK_PropertySymbol:
case SYMKIND.SK_FieldSymbol:
case SYMKIND.SK_EventSymbol:
Debug.Assert(atsCheck != null);
break;
}
#endif // DEBUG
ACCESSERROR error = CheckAccessCore(symCheck, atsCheck, symWhere, typeThru);
if (ACCESSERROR.ACCESSERROR_NOERROR != error)
{
return error;
}
// Check the accessibility of the return CType.
CType CType = symCheck.getType();
if (CType == null)
{
return ACCESSERROR.ACCESSERROR_NOERROR;
}
// For members of AGGSYMs, atsCheck should always be specified!
Debug.Assert(atsCheck != null);
if (atsCheck.getAggregate().IsSource())
{
// We already check the "at least as accessible as" rules.
// Does this always work for generics?
// Could we get a bad CType argument in typeThru?
// Maybe call CheckTypeAccess on typeThru?
return ACCESSERROR.ACCESSERROR_NOERROR;
}
// Substitute on the CType.
if (atsCheck.GetTypeArgsAll().size > 0)
{
CType = SymbolLoader.GetTypeManager().SubstType(CType, atsCheck);
}
return CheckTypeAccess(CType, symWhere) ? ACCESSERROR.ACCESSERROR_NOERROR : ACCESSERROR.ACCESSERROR_NOACCESS;
}
示例2: CheckAccessCore
//
// SymbolLoader forwarders (end)
/////////////////////////////////////////////////////////////////////////////////
//
// Utility methods
//
protected ACCESSERROR CheckAccessCore(Symbol symCheck, AggregateType atsCheck, Symbol symWhere, CType typeThru)
{
Debug.Assert(symCheck != null);
Debug.Assert(atsCheck == null || symCheck.parent == atsCheck.getAggregate());
Debug.Assert(typeThru == null ||
typeThru.IsAggregateType() ||
typeThru.IsTypeParameterType() ||
typeThru.IsArrayType() ||
typeThru.IsNullableType() ||
typeThru.IsErrorType());
switch (symCheck.GetAccess())
{
default:
throw Error.InternalCompilerError();
//return ACCESSERROR.ACCESSERROR_NOACCESS;
case ACCESS.ACC_UNKNOWN:
return ACCESSERROR.ACCESSERROR_NOACCESS;
case ACCESS.ACC_PUBLIC:
return ACCESSERROR.ACCESSERROR_NOERROR;
case ACCESS.ACC_PRIVATE:
case ACCESS.ACC_PROTECTED:
if (symWhere == null)
{
return ACCESSERROR.ACCESSERROR_NOACCESS;
}
break;
case ACCESS.ACC_INTERNAL:
case ACCESS.ACC_INTERNALPROTECTED: // Check internal, then protected.
if (symWhere == null)
{
return ACCESSERROR.ACCESSERROR_NOACCESS;
}
if (symWhere.SameAssemOrFriend(symCheck))
{
return ACCESSERROR.ACCESSERROR_NOERROR;
}
if (symCheck.GetAccess() == ACCESS.ACC_INTERNAL)
{
return ACCESSERROR.ACCESSERROR_NOACCESS;
}
break;
}
// Should always have atsCheck for private and protected access check.
// We currently don't need it since access doesn't respect instantiation.
// We just use symWhere.parent.AsAggregateSymbol() instead.
AggregateSymbol aggCheck = symCheck.parent.AsAggregateSymbol();
// Find the inner-most enclosing AggregateSymbol.
AggregateSymbol aggWhere = null;
for (Symbol symT = symWhere; symT != null; symT = symT.parent)
{
if (symT.IsAggregateSymbol())
{
aggWhere = symT.AsAggregateSymbol();
break;
}
if (symT.IsAggregateDeclaration())
{
aggWhere = symT.AsAggregateDeclaration().Agg();
break;
}
}
if (aggWhere == null)
{
return ACCESSERROR.ACCESSERROR_NOACCESS;
}
// First check for private access.
for (AggregateSymbol agg = aggWhere; agg != null; agg = agg.GetOuterAgg())
{
if (agg == aggCheck)
{
return ACCESSERROR.ACCESSERROR_NOERROR;
}
}
if (symCheck.GetAccess() == ACCESS.ACC_PRIVATE)
{
return ACCESSERROR.ACCESSERROR_NOACCESS;
}
// Handle the protected case - which is the only real complicated one.
Debug.Assert(symCheck.GetAccess() == ACCESS.ACC_PROTECTED || symCheck.GetAccess() == ACCESS.ACC_INTERNALPROTECTED);
//.........这里部分代码省略.........
示例3: LowerBoundArrayInference
////////////////////////////////////////////////////////////////////////////////
private bool LowerBoundArrayInference(CType pSource, CType pDest)
{
// SPEC: Otherwise, if U is an array CType Ue[...] and V is either an array
// SPEC: CType Ve[...] of the same rank, or if U is a one-dimensional array
// SPEC: CType Ue[] and V is one of IEnumerable<Ve>, ICollection<Ve>,
// SPEC: IList<Ve>, IReadOnlyCollection<Ve> or IReadOnlyList<Ve> then
// SPEC: if Ue is known to be a reference CType then a lower-bound inference
// SPEC: from Ue to Ve is made.
// SPEC: otherwise an exact inference from Ue to Ve is made.
// Consider the following:
//
// abstract class B<T> { public abstract M<U>(U u) : where U : T; }
// class D : B<int[]> {
// static void M<X>(X[] x) { }
// public override M<U>(U u) { M(u); } // should infer M<int>
// }
if (pSource.IsTypeParameterType())
{
pSource = pSource.AsTypeParameterType().GetEffectiveBaseClass();
}
if (!pSource.IsArrayType())
{
return false;
}
ArrayType pArraySource = pSource.AsArrayType();
CType pElementSource = pArraySource.GetElementType();
CType pElementDest = null;
if (pDest.IsArrayType())
{
ArrayType pArrayDest = pDest.AsArrayType();
if (pArrayDest.rank != pArraySource.rank)
{
return false;
}
pElementDest = pArrayDest.GetElementType();
}
else if (pDest.isPredefType(PredefinedType.PT_G_IENUMERABLE) ||
pDest.isPredefType(PredefinedType.PT_G_ICOLLECTION) ||
pDest.isPredefType(PredefinedType.PT_G_ILIST) ||
pDest.isPredefType(PredefinedType.PT_G_IREADONLYCOLLECTION) ||
pDest.isPredefType(PredefinedType.PT_G_IREADONLYLIST))
{
if (pArraySource.rank != 1)
{
return false;
}
AggregateType pAggregateDest = pDest.AsAggregateType();
pElementDest = pAggregateDest.GetTypeArgsThis().Item(0);
}
else
{
return false;
}
if (pElementSource.IsRefType())
{
LowerBoundInference(pElementSource, pElementDest);
}
else
{
ExactInference(pElementSource, pElementDest);
}
return true;
}
示例4: UpperBoundArrayInference
////////////////////////////////////////////////////////////////////////////////
private bool UpperBoundArrayInference(CType pSource, CType pDest)
{
// SPEC: Otherwise, if V is an array CType Ve[...] and U is an array
// SPEC: CType Ue[...] of the same rank, or if V is a one-dimensional array
// SPEC: CType Ve[] and U is one of IEnumerable<Ue>, ICollection<Ue>,
// SPEC: IList<Ue>, IReadOnlyCollection<Ue> or IReadOnlyList<Ue> then
// SPEC: if Ue is known to be a reference CType then an upper-bound inference
// SPEC: from Ue to Ve is made.
// SPEC: otherwise an exact inference from Ue to Ve is made.
if (!pDest.IsArrayType())
{
return false;
}
ArrayType pArrayDest = pDest.AsArrayType();
CType pElementDest = pArrayDest.GetElementType();
CType pElementSource = null;
if (pSource.IsArrayType())
{
ArrayType pArraySource = pSource.AsArrayType();
if (pArrayDest.rank != pArraySource.rank)
{
return false;
}
pElementSource = pArraySource.GetElementType();
}
else if (pSource.isPredefType(PredefinedType.PT_G_IENUMERABLE) ||
pSource.isPredefType(PredefinedType.PT_G_ICOLLECTION) ||
pSource.isPredefType(PredefinedType.PT_G_ILIST) ||
pSource.isPredefType(PredefinedType.PT_G_IREADONLYLIST) ||
pSource.isPredefType(PredefinedType.PT_G_IREADONLYCOLLECTION))
{
if (pArrayDest.rank != 1)
{
return false;
}
AggregateType pAggregateSource = pSource.AsAggregateType();
pElementSource = pAggregateSource.GetTypeArgsThis().Item(0);
}
else
{
return false;
}
if (pElementSource.IsRefType())
{
UpperBoundInference(pElementSource, pElementDest);
}
else
{
ExactInference(pElementSource, pElementDest);
}
return true;
}
示例5: GetBestAccessibleType
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// RUNTIME BINDER ONLY CHANGE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
internal bool GetBestAccessibleType(CSemanticChecker semanticChecker, BindingContext bindingContext, CType typeSrc, out CType typeDst)
{
// This method implements the "best accessible type" algorithm for determining the type
// of untyped arguments in the runtime binder. It is also used in method type inference
// to fix type arguments to types that are accessible.
// The new type is returned in an out parameter. The result will be true (and the out param
// non-null) only when the algorithm could find a suitable accessible type.
Debug.Assert(semanticChecker != null);
Debug.Assert(bindingContext != null);
Debug.Assert(typeSrc != null);
typeDst = null;
if (semanticChecker.CheckTypeAccess(typeSrc, bindingContext.ContextForMemberLookup()))
{
// If we already have an accessible type, then use it. This is the terminal point of the recursion.
typeDst = typeSrc;
return true;
}
// These guys have no accessibility concerns.
Debug.Assert(!typeSrc.IsVoidType() && !typeSrc.IsErrorType() && !typeSrc.IsTypeParameterType());
if (typeSrc.IsParameterModifierType() || typeSrc.IsPointerType())
{
// We cannot vary these.
return false;
}
CType intermediateType;
if ((typeSrc.isInterfaceType() || typeSrc.isDelegateType()) && TryVarianceAdjustmentToGetAccessibleType(semanticChecker, bindingContext, typeSrc.AsAggregateType(), out intermediateType))
{
// If we have an interface or delegate type, then it can potentially be varied by its type arguments
// to produce an accessible type, and if that's the case, then return that.
// Example: IEnumerable<PrivateConcreteFoo> --> IEnumerable<PublicAbstractFoo>
typeDst = intermediateType;
Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
return true;
}
if (typeSrc.IsArrayType() && TryArrayVarianceAdjustmentToGetAccessibleType(semanticChecker, bindingContext, typeSrc.AsArrayType(), out intermediateType))
{
// Similarly to the interface and delegate case, arrays are covariant in their element type and
// so we can potentially produce an array type that is accessible.
// Example: PrivateConcreteFoo[] --> PublicAbstractFoo[]
typeDst = intermediateType;
Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
return true;
}
if (typeSrc.IsNullableType())
{
// We have an inaccessible nullable type, which means that the best we can do is System.ValueType.
typeDst = this.GetOptPredefAgg(PredefinedType.PT_VALUE).getThisType();
Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
return true;
}
if (typeSrc.IsArrayType())
{
// We have an inaccessible array type for which we could not earlier find a better array type
// with a covariant conversion, so the best we can do is System.Array.
typeDst = this.GetReqPredefAgg(PredefinedType.PT_ARRAY).getThisType();
Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
return true;
}
Debug.Assert(typeSrc.IsAggregateType());
if (typeSrc.IsAggregateType())
{
// We have an AggregateType, so recurse on its base class.
AggregateType aggType = typeSrc.AsAggregateType();
AggregateType baseType = aggType.GetBaseClass();
if (baseType == null)
{
// This happens with interfaces, for instance. But in that case, the
// conversion to object does exist, is an implicit reference conversion,
// and so we will use it.
baseType = this.GetReqPredefAgg(PredefinedType.PT_OBJECT).getThisType();
}
return GetBestAccessibleType(semanticChecker, bindingContext, baseType, out typeDst);
}
return false;
}
示例6: ExactArrayInference
////////////////////////////////////////////////////////////////////////////////
private bool ExactArrayInference(CType pSource, CType pDest)
{
// SPEC: Otherwise, if U is an array CType UE[...] and V is an array CType VE[...]
// SPEC: of the same rank then an exact inference from UE to VE is made.
if (!pSource.IsArrayType() || !pDest.IsArrayType())
{
return false;
}
ArrayType pArraySource = pSource.AsArrayType();
ArrayType pArrayDest = pDest.AsArrayType();
if (pArraySource.rank != pArrayDest.rank)
{
return false;
}
ExactInference(pArraySource.GetElementType(), pArrayDest.GetElementType());
return true;
}
示例7: conversion
/***************************************************************************************************
Determine whether there is an explicit or implicit reference conversion (or identity conversion)
from typeSrc to typeDst. This is when:
13.2.3 Explicit reference conversions
The explicit reference conversions are:
* From object to any reference-type.
* From any class-type S to any class-type T, provided S is a base class of T.
* From any class-type S to any interface-type T, provided S is not sealed and provided S does not implement T.
* From any interface-type S to any class-type T, provided T is not sealed or provided T implements S.
* From any interface-type S to any interface-type T, provided S is not derived from T.
* From an array-type S with an element type SE to an array-type T with an element type TE, provided all of the following are true:
o S and T differ only in element type. (In other words, S and T have the same number of dimensions.)
o An explicit reference conversion exists from SE to TE.
* From System.Array and the interfaces it implements, to any array-type.
* From System.Delegate and the interfaces it implements, to any delegate-type.
* From a one-dimensional array-type S[] to System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyList<T> and their base interfaces, provided there is an explicit reference conversion from S to T.
* From a generic delegate type S to generic delegate type T, provided all of the follow are true:
o Both types are constructed generic types of the same generic delegate type, D<X1,... Xk>.That is,
S is D<S1,... Sk> and T is D<T1,... Tk>.
o S is not compatible with or identical to T.
o If type parameter Xi is declared to be invariant then Si must be identical to Ti.
o If type parameter Xi is declared to be covariant ("out") then Si must be convertible
to Ti via an identify conversion, implicit reference conversion, or explicit reference conversion.
o If type parameter Xi is declared to be contravariant ("in") then either Si must be identical to Ti,
or Si and Ti must both be reference types.
* From System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyList<T> and their base interfaces to a one-dimensional array-type S[], provided there is an implicit or explicit reference conversion from S[] to System.Collections.Generic.IList<T> or System.Collections.Generic.IReadOnlyList<T>. This is precisely when either S and T are the same type or there is an implicit or explicit reference conversion from S to T.
For a type-parameter T that is known to be a reference type (§25.7), the following explicit reference conversions exist:
* From the effective base class C of T to T and from any base class of C to T.
* From any interface-type to T.
* From T to any interface-type I provided there isn’t already an implicit reference conversion from T to I.
* From a type-parameter U to T provided that T depends on U (§25.7). [Note: Since T is known to be a reference type, within the scope of T, the run-time type of U will always be a reference type, even if U is not known to be a reference type at compile-time. end note]
* Both src and dst are reference types and there is a builtin explicit conversion from
src to dst.
* Or src is a reference type and dst is a base type of src (in which case the conversion is
implicit as well).
* Or dst is a reference type and src is a base type of dst.
The latter two cases can happen with type variables even though the other type variable is not
a reference type.
***************************************************************************************************/
public static bool FExpRefConv(SymbolLoader loader, CType typeSrc, CType typeDst)
{
Debug.Assert(typeSrc != null);
Debug.Assert(typeDst != null);
if (typeSrc.IsRefType() && typeDst.IsRefType())
{
// is there an implicit reference conversion in either direction?
// this handles the bulk of the cases ...
if (loader.HasIdentityOrImplicitReferenceConversion(typeSrc, typeDst) ||
loader.HasIdentityOrImplicitReferenceConversion(typeDst, typeSrc))
{
return true;
}
// For a type-parameter T that is known to be a reference type (§25.7), the following explicit reference conversions exist:
// • From any interface-type to T.
// • From T to any interface-type I provided there isn’t already an implicit reference conversion from T to I.
if (typeSrc.isInterfaceType() && typeDst.IsTypeParameterType())
{
return true;
}
if (typeSrc.IsTypeParameterType() && typeDst.isInterfaceType())
{
return true;
}
// * From any class-type S to any interface-type T, provided S is not sealed
// * From any interface-type S to any class-type T, provided T is not sealed
// * From any interface-type S to any interface-type T, provided S is not derived from T.
if (typeSrc.IsAggregateType() && typeDst.IsAggregateType())
{
AggregateSymbol aggSrc = typeSrc.AsAggregateType().getAggregate();
AggregateSymbol aggDest = typeDst.AsAggregateType().getAggregate();
if ((aggSrc.IsClass() && !aggSrc.IsSealed() && aggDest.IsInterface()) ||
(aggSrc.IsInterface() && aggDest.IsClass() && !aggDest.IsSealed()) ||
(aggSrc.IsInterface() && aggDest.IsInterface()))
{
return true;
}
}
// * From an array-type S with an element type SE to an array-type T with an element type TE, provided all of the following are true:
// o S and T differ only in element type. (In other words, S and T have the same number of dimensions.)
// o An explicit reference conversion exists from SE to TE.
if (typeSrc.IsArrayType() && typeDst.IsArrayType())
{
return typeSrc.AsArrayType().rank == typeDst.AsArrayType().rank && FExpRefConv(loader, typeSrc.AsArrayType().GetElementType(), typeDst.AsArrayType().GetElementType());
}
// * From a one-dimensional array-type S[] to System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyList<T>
// and their base interfaces, provided there is an explicit reference conversion from S to T.
if (typeSrc.IsArrayType())
{
if (typeSrc.AsArrayType().rank != 1 ||
!typeDst.isInterfaceType() || typeDst.AsAggregateType().GetTypeArgsAll().Size != 1)
//.........这里部分代码省略.........
示例8: SatisfiesBound
////////////////////////////////////////////////////////////////////////////////
// Determine whether the arg type satisfies the typeBnd constraint. Note that
// typeBnd could be just about any type (since we added naked type parameter
// constraints).
private static bool SatisfiesBound(CSemanticChecker checker, CType arg, CType typeBnd)
{
if (typeBnd == arg)
return true;
switch (typeBnd.GetTypeKind())
{
default:
Debug.Assert(false, "Unexpected type.");
return false;
case TypeKind.TK_VoidType:
case TypeKind.TK_PointerType:
case TypeKind.TK_ErrorType:
return false;
case TypeKind.TK_ArrayType:
case TypeKind.TK_TypeParameterType:
break;
case TypeKind.TK_NullableType:
typeBnd = typeBnd.AsNullableType().GetAts(checker.GetErrorContext());
if (null == typeBnd)
return true;
break;
case TypeKind.TK_AggregateType:
break;
}
Debug.Assert(typeBnd.IsAggregateType() || typeBnd.IsTypeParameterType() || typeBnd.IsArrayType());
switch (arg.GetTypeKind())
{
default:
return false;
case TypeKind.TK_ErrorType:
case TypeKind.TK_PointerType:
return false;
case TypeKind.TK_NullableType:
arg = arg.AsNullableType().GetAts(checker.GetErrorContext());
if (null == arg)
return true;
// Fall through.
goto case TypeKind.TK_TypeParameterType;
case TypeKind.TK_TypeParameterType:
case TypeKind.TK_ArrayType:
case TypeKind.TK_AggregateType:
return checker.GetSymbolLoader().HasBaseConversion(arg, typeBnd);
}
}
示例9: HasImplicitReferenceConversion
public bool HasImplicitReferenceConversion(CType pSource, CType pDest)
{
Debug.Assert(pSource != null);
Debug.Assert(pDest != null);
// The implicit reference conversions are:
// * From any reference type to Object.
if (pSource.IsRefType() && pDest.isPredefType(PredefinedType.PT_OBJECT))
{
return true;
}
// * From any class type S to any class type T provided S is derived from T.
if (pSource.isClassType() && pDest.isClassType() && IsBaseClass(pSource, pDest))
{
return true;
}
// ORIGINAL RULES:
// // * From any class type S to any interface type T provided S implements T.
// if (pSource.isClassType() && pDest.isInterfaceType() && IsBaseInterface(pSource, pDest))
// {
// return true;
// }
// // * from any interface type S to any interface type T, provided S is derived from T.
// if (pSource.isInterfaceType() && pDest.isInterfaceType() && IsBaseInterface(pSource, pDest))
// {
// return true;
// }
// VARIANCE EXTENSIONS:
// * From any class type S to any interface type T provided S implements an interface
// convertible to T.
// * From any interface type S to any interface type T provided S implements an interface
// convertible to T.
// * From any interface type S to any interface type T provided S is not T and S is
// an interface convertible to T.
if (pSource.isClassType() && pDest.isInterfaceType() && HasAnyBaseInterfaceConversion(pSource, pDest))
{
return true;
}
if (pSource.isInterfaceType() && pDest.isInterfaceType() && HasAnyBaseInterfaceConversion(pSource, pDest))
{
return true;
}
if (pSource.isInterfaceType() && pDest.isInterfaceType() && pSource != pDest &&
HasInterfaceConversion(pSource.AsAggregateType(), pDest.AsAggregateType()))
{
return true;
}
// * From an array type S with an element type SE to an array type T with element type TE
// provided that all of the following are true:
// * S and T differ only in element type. In other words, S and T have the same number of dimensions.
// * Both SE and TE are reference types.
// * An implicit reference conversion exists from SE to TE.
if (pSource.IsArrayType() && pDest.IsArrayType() &&
HasCovariantArrayConversion(pSource.AsArrayType(), pDest.AsArrayType()))
{
return true;
}
// * From any array type to System.Array or any interface implemented by System.Array.
if (pSource.IsArrayType() && (pDest.isPredefType(PredefinedType.PT_ARRAY) ||
IsBaseInterface(GetReqPredefType(PredefinedType.PT_ARRAY, false), pDest)))
{
return true;
}
// * From a single-dimensional array type S[] to IList<T> and its base
// interfaces, provided that there is an implicit identity or reference
// conversion from S to T.
if (pSource.IsArrayType() && HasArrayConversionToInterface(pSource.AsArrayType(), pDest))
{
return true;
}
// * From any delegate type to System.Delegate
//
// SPEC OMISSION:
//
// The spec should actually say
//
// * From any delegate type to System.Delegate
// * From any delegate type to System.MulticastDelegate
// * From any delegate type to any interface implemented by System.MulticastDelegate
if (pSource.isDelegateType() &&
(pDest.isPredefType(PredefinedType.PT_MULTIDEL) ||
pDest.isPredefType(PredefinedType.PT_DELEGATE) ||
IsBaseInterface(GetReqPredefType(PredefinedType.PT_MULTIDEL, false), pDest)))
{
return true;
}
// VARIANCE EXTENSION:
// * From any delegate type S to a delegate type T provided S is not T and
// S is a delegate convertible to T
if (pSource.isDelegateType() && pDest.isDelegateType() &&
HasDelegateConversion(pSource.AsAggregateType(), pDest.AsAggregateType()))
{
return true;
//.........这里部分代码省略.........
示例10: GetAggTypeSym
// It would be nice to make this a virtual method on typeSym.
public AggregateType GetAggTypeSym(CType typeSym)
{
Debug.Assert(typeSym != null);
Debug.Assert(typeSym.IsAggregateType() ||
typeSym.IsTypeParameterType() ||
typeSym.IsArrayType() ||
typeSym.IsNullableType());
switch (typeSym.GetTypeKind())
{
case TypeKind.TK_AggregateType:
return typeSym.AsAggregateType();
case TypeKind.TK_ArrayType:
return GetReqPredefType(PredefinedType.PT_ARRAY);
case TypeKind.TK_TypeParameterType:
return typeSym.AsTypeParameterType().GetEffectiveBaseClass();
case TypeKind.TK_NullableType:
return typeSym.AsNullableType().GetAts(ErrorContext);
}
Debug.Assert(false, "Bad typeSym!");
return null;
}
示例11: ErrAppendType
//.........这里部分代码省略.........
ErrAppendId(MessageID.NULL);
break;
case TypeKind.TK_OpenTypePlaceholderType:
// Leave blank.
break;
case TypeKind.TK_BoundLambdaType:
ErrAppendId(MessageID.AnonMethod);
break;
case TypeKind.TK_UnboundLambdaType:
ErrAppendId(MessageID.Lambda);
break;
case TypeKind.TK_MethodGroupType:
ErrAppendId(MessageID.MethodGroup);
break;
case TypeKind.TK_ArgumentListType:
ErrAppendString(TokenFacts.GetText(TokenKind.ArgList));
break;
case TypeKind.TK_ArrayType:
{
CType elementType = pType.AsArrayType().GetBaseElementType();
int rank;
if (null == elementType)
{
Debug.Assert(false, "No element type");
break;
}
ErrAppendType(elementType, pctx);
for (elementType = pType;
elementType != null && elementType.IsArrayType();
elementType = elementType.AsArrayType().GetElementType())
{
rank = elementType.AsArrayType().rank;
// Add [] with (rank-1) commas inside
ErrAppendChar('[');
#if ! CSEE
// known rank.
if (rank > 1)
{
ErrAppendChar('*');
}
#endif
for (int i = rank; i > 1; --i)
{
ErrAppendChar(',');
#if ! CSEE
ErrAppendChar('*');
#endif
}
ErrAppendChar(']');
}
break;
}
case TypeKind.TK_VoidType:
ErrAppendName(GetNameManager().Lookup(TokenFacts.GetText(TokenKind.Void)));
break;
case TypeKind.TK_ParameterModifierType:
// add ref or out
ErrAppendString(pType.AsParameterModifierType().isOut ? "out " : "ref ");
// add base type name
ErrAppendType(pType.AsParameterModifierType().GetParameterType(), pctx);
break;
case TypeKind.TK_PointerType:
// Generate the base type.
ErrAppendType(pType.AsPointerType().GetReferentType(), pctx);
{
// add the trailing *
ErrAppendChar('*');
}
break;
case TypeKind.TK_NullableType:
ErrAppendType(pType.AsNullableType().GetUnderlyingType(), pctx);
ErrAppendChar('?');
break;
case TypeKind.TK_NaturalIntegerType:
default:
// Shouldn't happen.
Debug.Assert(false, "Bad type kind");
break;
}
}