本文整理汇总了C#中Microsoft.CSharp.RuntimeBinder.Semantics.CType.isPredefType方法的典型用法代码示例。如果您正苦于以下问题:C# CType.isPredefType方法的具体用法?C# CType.isPredefType怎么用?C# CType.isPredefType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.RuntimeBinder.Semantics.CType
的用法示例。
在下文中一共展示了CType.isPredefType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: BindIncOpCore
private EXPR BindIncOpCore(ExpressionKind ek, EXPRFLAG flags, EXPR exprVal, CType type)
{
Debug.Assert(ek == ExpressionKind.EK_ADD || ek == ExpressionKind.EK_SUB);
CONSTVAL cv = new CONSTVAL();
EXPR pExprResult = null;
if (type.isEnumType() && type.fundType() > FUNDTYPE.FT_LASTINTEGRAL)
{
// This is an error case when enum derives from an illegal type. Just treat it as an int.
type = GetReqPDT(PredefinedType.PT_INT);
}
FUNDTYPE ft = type.fundType();
CType typeTmp = type;
switch (ft)
{
default:
{
Debug.Assert(type.isPredefType(PredefinedType.PT_DECIMAL));
ek = ek == ExpressionKind.EK_ADD ? ExpressionKind.EK_DECIMALINC : ExpressionKind.EK_DECIMALDEC;
PREDEFMETH predefMeth = ek == ExpressionKind.EK_DECIMALINC ? PREDEFMETH.PM_DECIMAL_OPINCREMENT : PREDEFMETH.PM_DECIMAL_OPDECREMENT;
pExprResult = CreateUnaryOpForPredefMethodCall(ek, predefMeth, type, exprVal);
}
break;
case FUNDTYPE.FT_PTR:
cv.iVal = 1;
pExprResult = BindPtrBinOp(ek, flags, exprVal, GetExprFactory().CreateConstant(GetReqPDT(PredefinedType.PT_INT), cv));
break;
case FUNDTYPE.FT_I1:
case FUNDTYPE.FT_I2:
case FUNDTYPE.FT_U1:
case FUNDTYPE.FT_U2:
typeTmp = GetReqPDT(PredefinedType.PT_INT);
cv.iVal = 1;
pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp);
break;
case FUNDTYPE.FT_I4:
case FUNDTYPE.FT_U4:
cv.iVal = 1;
pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp);
break;
case FUNDTYPE.FT_I8:
case FUNDTYPE.FT_U8:
cv = GetExprConstants().Create((long)1);
pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp);
break;
case FUNDTYPE.FT_R4:
case FUNDTYPE.FT_R8:
cv = GetExprConstants().Create(1.0);
pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp);
break;
}
Debug.Assert(pExprResult != null);
Debug.Assert(!pExprResult.type.IsNullableType());
return pExprResult;
}
示例4: HasBaseConversion
public bool HasBaseConversion(CType pSource, CType pDest)
{
// By a "base conversion" we mean:
//
// * an identity conversion
// * an implicit reference conversion
// * an implicit boxing conversion
// * an implicit type parameter conversion
//
// In other words, these are conversions that can be made to a base
// class, base interface or co/contravariant type without any change in
// representation other than boxing. A conversion from, say, int to double,
// is NOT a "base conversion", because representation is changed. A conversion
// from, say, lambda to expression tree is not a "base conversion" because
// do not have a type.
//
// The existence of a base conversion depends solely upon the source and
// destination types, not the source expression.
//
// This notion is not found in the spec but it is useful in the implementation.
if (pSource.IsAggregateType() && pDest.isPredefType(PredefinedType.PT_OBJECT))
{
// If we are going from any aggregate type (class, struct, interface, enum or delegate)
// to object, we immediately return true. This may seem like a mere optimization --
// after all, if we have an aggregate then we have some kind of implicit conversion
// to object.
//
// However, it is not a mere optimization; this introduces a control flow change
// in error reporting scenarios for unresolved type forwarders. If a type forwarder
// cannot be resolved then the resulting type symbol will be an aggregate, but
// we will not be able to classify it into class, struct, etc.
//
// We know that we will have an error in this case; we do not wish to compound
// that error by giving a spurious "you cannot convert this thing to object"
// error, which, after all, will go away when the type forwarding problem is
// fixed.
return true;
}
if (HasIdentityOrImplicitReferenceConversion(pSource, pDest))
{
return true;
}
if (HasImplicitBoxingConversion(pSource, pDest))
{
return true;
}
if (pSource.IsTypeParameterType() &&
HasImplicitTypeParameterBaseConversion(pSource.AsTypeParameterType(), pDest))
{
return true;
}
return false;
}
示例5: 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;
//.........这里部分代码省略.........
示例6: HasArrayConversionToInterface
private bool HasArrayConversionToInterface(ArrayType pSource, CType pDest)
{
Debug.Assert(pSource != null);
Debug.Assert(pDest != null);
if (pSource.rank != 1)
{
return false;
}
if (!pDest.isInterfaceType())
{
return false;
}
// * From a single-dimensional array type S[] to IList<T> or IReadOnlyList<T> and their base
// interfaces, provided that there is an implicit identity or reference
// conversion from S to T.
// We only have six interfaces to check. IList<T>, IReadOnlyList<T> and their bases:
// * The base interface of IList<T> is ICollection<T>.
// * The base interface of ICollection<T> is IEnumerable<T>.
// * The base interface of IEnumerable<T> is IEnumerable.
// * The base interface of IReadOnlyList<T> is IReadOnlyCollection<T>.
// * The base interface of IReadOnlyCollection<T> is IEnumerable<T>.
if (pDest.isPredefType(PredefinedType.PT_IENUMERABLE))
{
return true;
}
AggregateType atsDest = pDest.AsAggregateType();
AggregateSymbol aggDest = pDest.getAggregate();
if (!aggDest.isPredefAgg(PredefinedType.PT_G_ILIST) &&
!aggDest.isPredefAgg(PredefinedType.PT_G_ICOLLECTION) &&
!aggDest.isPredefAgg(PredefinedType.PT_G_IENUMERABLE) &&
!aggDest.isPredefAgg(PredefinedType.PT_G_IREADONLYCOLLECTION) &&
!aggDest.isPredefAgg(PredefinedType.PT_G_IREADONLYLIST))
{
return false;
}
Debug.Assert(atsDest.GetTypeArgsAll().Size == 1);
CType pSourceElement = pSource.GetElementType();
CType pDestTypeArgument = atsDest.GetTypeArgsAll().Item(0);
return HasIdentityOrImplicitReferenceConversion(pSourceElement, pDestTypeArgument);
}