本文整理汇总了C#中Microsoft.CSharp.RuntimeBinder.Semantics.TypeArray.Item方法的典型用法代码示例。如果您正苦于以下问题:C# TypeArray.Item方法的具体用法?C# TypeArray.Item怎么用?C# TypeArray.Item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.RuntimeBinder.Semantics.TypeArray
的用法示例。
在下文中一共展示了TypeArray.Item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NumberOfErrorTypes
/////////////////////////////////////////////////////////////////////////////////
private static int NumberOfErrorTypes(TypeArray pTypeArgs)
{
int nCount = 0;
for (int i = 0; i < pTypeArgs.Size; i++)
{
if (pTypeArgs.Item(i).IsErrorType())
{
nCount++;
}
}
return nCount;
}
示例2: IsBetterThanCurrent
private static bool IsBetterThanCurrent(TypeArray pTypeArgs1, TypeArray pTypeArgs2)
{
int leftErrors = NumberOfErrorTypes(pTypeArgs1);
int rightErrors = NumberOfErrorTypes(pTypeArgs2);
if (leftErrors == rightErrors)
{
int max = pTypeArgs1.Size > pTypeArgs2.Size ? pTypeArgs2.Size : pTypeArgs1.Size;
// If we dont have a winner yet, go through each element's type args.
for (int i = 0; i < max; i++)
{
if (pTypeArgs1.Item(i).IsAggregateType())
{
leftErrors += NumberOfErrorTypes(pTypeArgs1.Item(i).AsAggregateType().GetTypeArgsAll());
}
if (pTypeArgs2.Item(i).IsAggregateType())
{
rightErrors += NumberOfErrorTypes(pTypeArgs2.Item(i).AsAggregateType().GetTypeArgsAll());
}
}
}
return rightErrors < leftErrors;
}
示例3: TypeContainsTyVars
public static bool TypeContainsTyVars(CType type, TypeArray typeVars)
{
LRecurse: // Label used for "tail" recursion.
switch (type.GetTypeKind())
{
default:
Debug.Assert(false, "Bad Symbol kind in TypeContainsTyVars");
return false;
case TypeKind.TK_UnboundLambdaType:
case TypeKind.TK_BoundLambdaType:
case TypeKind.TK_NullType:
case TypeKind.TK_VoidType:
case TypeKind.TK_OpenTypePlaceholderType:
case TypeKind.TK_MethodGroupType:
return false;
case TypeKind.TK_ArrayType:
case TypeKind.TK_NullableType:
case TypeKind.TK_ParameterModifierType:
case TypeKind.TK_PointerType:
type = type.GetBaseOrParameterOrElementType();
goto LRecurse;
case TypeKind.TK_AggregateType:
{ // BLOCK
AggregateType ats = type.AsAggregateType();
for (int i = 0; i < ats.GetTypeArgsAll().Size; i++)
{
if (TypeContainsTyVars(ats.GetTypeArgsAll().Item(i), typeVars))
{
return true;
}
}
}
return false;
case TypeKind.TK_ErrorType:
if (type.AsErrorType().HasParent())
{
ErrorType err = type.AsErrorType();
Debug.Assert(err.nameText != null && err.typeArgs != null);
for (int i = 0; i < err.typeArgs.Size; i++)
{
if (TypeContainsTyVars(err.typeArgs.Item(i), typeVars))
{
return true;
}
}
if (err.HasTypeParent())
{
type = err.GetTypeParent();
goto LRecurse;
}
}
return false;
case TypeKind.TK_TypeParameterType:
if (typeVars != null && typeVars.Size > 0)
{
int ivar = type.AsTypeParameterType().GetIndexInTotalParameters();
return ivar < typeVars.Size && type == typeVars.Item(ivar);
}
return true;
}
}
示例4: SubstEqualTypeArrays
public bool SubstEqualTypeArrays(TypeArray taDst, TypeArray taSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst)
{
// Handle the simple common cases first.
if (taDst == taSrc || (taDst != null && taDst.Equals(taSrc)))
{
// The following assertion is not always true and indicates a problem where
// the signature of override method does not match the one inherited from
// the base class. The method match we have found does not take the type
// arguments of the base class into account. So actually we are not overriding
// the method that we "intend" to.
// Debug.Assert(taDst == SubstTypeArray(taSrc, typeArgsCls, typeArgsMeth, grfst));
return true;
}
if (taDst.Size != taSrc.Size)
return false;
if (taDst.Size == 0)
return true;
var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst);
if (ctx.FNop())
return false;
for (int i = 0; i < taDst.size; i++)
{
if (!SubstEqualTypesCore(taDst.Item(i), taSrc.Item(i), ctx))
return false;
}
return true;
}
示例5: SubstTypeArray
public TypeArray SubstTypeArray(TypeArray taSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, SubstTypeFlags grfst)
{
if (taSrc == null || taSrc.Size == 0)
return taSrc;
var ctx = new SubstContext(typeArgsCls, typeArgsMeth, grfst);
if (ctx.FNop())
return taSrc;
CType[] prgpts = new CType[taSrc.Size];
for (int ipts = 0; ipts < taSrc.Size; ipts++)
{
prgpts[ipts] = SubstTypeCore(taSrc.Item(ipts), ctx);
}
return _BSymmgr.AllocParams(taSrc.Size, prgpts);
}
示例6: UpdateArguments
private void UpdateArguments()
{
// Parameter types might have changed as a result of
// method type inference.
_pCurrentParameters = _pExprBinder.GetTypes().SubstTypeArray(
_pCurrentParameters, _pCurrentType, _pCurrentTypeArgs);
// It is also possible that an optional argument has changed its value
// as a result of method type inference. For example, when inferring
// from Foo(10) to Foo<T>(T t1, T t2 = default(T)), the fabricated
// argument list starts off as being (10, default(T)). After type
// inference has successfully inferred T as int, it needs to be
// transformed into (10, default(int)) before applicability checking
// notices that default(T) is not assignable to int.
if (_pArguments.prgexpr == null || _pArguments.prgexpr.Count == 0)
{
return;
}
MethodOrPropertySymbol pMethod = null;
for (int iParam = 0; iParam < _pCurrentParameters.size; ++iParam)
{
EXPR pArgument = _pArguments.prgexpr[iParam];
if (!pArgument.IsOptionalArgument)
{
continue;
}
CType pType = _pCurrentParameters.Item(iParam);
if (pType == pArgument.type)
{
continue;
}
// Argument has changed its type because of method type inference. Recompute it.
if (pMethod == null)
{
pMethod = FindMostDerivedMethod(_pCurrentSym, _pGroup.GetOptionalObject());
Debug.Assert(pMethod != null);
}
Debug.Assert(pMethod.IsParameterOptional(iParam));
EXPR pArgumentNew = GenerateOptionalArgument(GetSymbolLoader(), _pExprBinder.GetExprFactory(), pMethod, _pCurrentParameters[iParam], iParam);
_pArguments.prgexpr[iParam] = pArgumentNew;
}
}
示例7: CheckConstraintsCore
////////////////////////////////////////////////////////////////////////////////
// Check whether typeArgs satisfies the constraints of typeVars. The
// typeArgsCls and typeArgsMeth are used for substitution on the bounds. The
// tree and symErr are used for error reporting.
private static bool CheckConstraintsCore(CSemanticChecker checker, ErrorHandling errHandling, Symbol symErr, TypeArray typeVars, TypeArray typeArgs, TypeArray typeArgsCls, TypeArray typeArgsMeth, CheckConstraintsFlags flags)
{
Debug.Assert(typeVars.size == typeArgs.size);
Debug.Assert(typeVars.size > 0);
Debug.Assert(flags == CheckConstraintsFlags.None || flags == CheckConstraintsFlags.NoErrors);
bool fError = false;
for (int i = 0; i < typeVars.size; i++)
{
// Empty bounds should be set to object.
TypeParameterType var = typeVars.ItemAsTypeParameterType(i);
CType arg = typeArgs.Item(i);
bool fOK = CheckSingleConstraint(checker, errHandling, symErr, var, arg, typeArgsCls, typeArgsMeth, flags);
fError |= !fOK;
}
return !fError;
}
示例8: ErrAppendTypeParameters
protected void ErrAppendTypeParameters(TypeArray @params, SubstContext pctx, bool forClass)
{
if (@params != null && @params.size != 0)
{
ErrAppendChar('<');
ErrAppendType(@params.Item(0), pctx);
for (int i = 1; i < @params.size; i++)
{
ErrAppendString(",");
ErrAppendType(@params.Item(i), pctx);
}
ErrAppendChar('>');
}
}
示例9: RearrangeNamedArguments
////////////////////////////////////////////////////////////////////////////////
// We need to rearange the method parameters so that the type of any specified named argument
// appears in the same place as the named argument. Consider the example below:
// Foo(int x = 4, string y = "", long l = 4)
// Foo(string y = "", string x="", long l = 5)
// and the call site:
// Foo(y:"a")
// After rearranging the parameter types we will have:
// (string, int, long) and (string, string, long)
// By rearranging the arguments as such we make sure that any specified named arguments appear in the same position for both
// methods and we also maintain the relative order of the other parameters (the type long appears after int in the above example)
private TypeArray RearrangeNamedArguments(TypeArray pta, MethPropWithInst mpwi,
CType pTypeThrough, ArgInfos args)
{
if (!args.fHasExprs)
{
return pta;
}
#if DEBUG
// We never have a named argument that is in a position in the argument
// list past the end of what would be the formal parameter list.
for (int i = pta.size; i < args.carg; i++)
{
Debug.Assert(!args.prgexpr[i].isNamedArgumentSpecification());
}
#endif
CType type = pTypeThrough != null ? pTypeThrough : mpwi.GetType();
CType[] typeList = new CType[pta.size];
MethodOrPropertySymbol methProp = GroupToArgsBinder.FindMostDerivedMethod(GetSymbolLoader(), mpwi.MethProp(), type);
// We initialize the new type array with the parameters for the method.
for (int iParam = 0; iParam < pta.size; iParam++)
{
typeList[iParam] = pta.Item(iParam);
}
// We then go over the specified arguments and put the type for any named argument in the right position in the array.
for (int iParam = 0; iParam < args.carg; iParam++)
{
EXPR arg = args.prgexpr[iParam];
if (arg.isNamedArgumentSpecification())
{
// We find the index of the type of the argument in the method parameter list and store that in a temp
int index = FindName(methProp.ParameterNames, arg.asNamedArgumentSpecification().Name);
CType tempType = pta.Item(index);
// Starting from the current position in the type list up until the location of the type of the optional argument
// We shift types by one:
// before: (int, string, long)
// after: (string, int, long)
// We only touch the types between the current position and the position of the type we need to move
for (int iShift = iParam; iShift < index; iShift++)
{
typeList[iShift + 1] = typeList[iShift];
}
typeList[iParam] = tempType;
}
}
return GetSymbolLoader().getBSymmgr().AllocParams(pta.size, typeList);
}
示例10: BindLiftedUDBinop
private EXPRCALL BindLiftedUDBinop(ExpressionKind ek, EXPR arg1, EXPR arg2, TypeArray Params, MethPropWithInst mpwi)
{
EXPR exprVal1 = arg1;
EXPR exprVal2 = arg2;
TypeArray paramsRaw;
CType typeRet;
CType typeRetRaw = GetTypes().SubstType(mpwi.Meth().RetType, mpwi.GetType());
// This is a lifted user defined operator. We know that both arguments
// go to the nullable formal parameter types, and that at least one
// of the arguments does not go to the non-nullable formal parameter type.
// (If both went to the non-nullable types then we would not be lifting.)
// We also know that the non-nullable type of the argument goes to the
// non-nullable type of formal parameter. However, if it does so only via
// a user-defined conversion then we should bind the conversion from the
// argument to the nullable formal parameter type first, before we then
// do the cast for the non-nullable call.
paramsRaw = GetTypes().SubstTypeArray(mpwi.Meth().Params, mpwi.GetType());
Debug.Assert(Params != paramsRaw);
Debug.Assert(paramsRaw.Item(0) == Params.Item(0).GetBaseOrParameterOrElementType());
Debug.Assert(paramsRaw.Item(1) == Params.Item(1).GetBaseOrParameterOrElementType());
if (!canConvert(arg1.type.StripNubs(), paramsRaw.Item(0), CONVERTTYPE.NOUDC))
{
exprVal1 = mustConvert(arg1, Params.Item(0));
}
if (!canConvert(arg2.type.StripNubs(), paramsRaw.Item(1), CONVERTTYPE.NOUDC))
{
exprVal2 = mustConvert(arg2, Params.Item(1));
}
EXPR nonLiftedArg1 = mustCast(exprVal1, paramsRaw.Item(0));
EXPR nonLiftedArg2 = mustCast(exprVal2, paramsRaw.Item(1));
switch (ek)
{
default:
typeRet = GetTypes().GetNullable(typeRetRaw);
break;
case ExpressionKind.EK_EQ:
case ExpressionKind.EK_NE:
Debug.Assert(paramsRaw.Item(0) == paramsRaw.Item(1));
Debug.Assert(typeRetRaw.isPredefType(PredefinedType.PT_BOOL));
// These ones don't lift the return type. Instead, if either side is null, the result is false.
typeRet = typeRetRaw;
break;
case ExpressionKind.EK_GT:
case ExpressionKind.EK_GE:
case ExpressionKind.EK_LT:
case ExpressionKind.EK_LE:
Debug.Assert(typeRetRaw.isPredefType(PredefinedType.PT_BOOL));
// These ones don't lift the return type. Instead, if either side is null, the result is false.
typeRet = typeRetRaw;
break;
}
// Now get the result for the pre-lifted call.
Debug.Assert(!(ek == ExpressionKind.EK_EQ || ek == ExpressionKind.EK_NE) || nonLiftedArg1.type == nonLiftedArg2.type);
EXPRCALL nonLiftedResult = BindUDBinopCall(nonLiftedArg1, nonLiftedArg2, paramsRaw, typeRetRaw, mpwi);
EXPRLIST args = GetExprFactory().CreateList(exprVal1, exprVal2);
EXPRMEMGRP pMemGroup = GetExprFactory().CreateMemGroup(null, mpwi);
EXPRCALL call = GetExprFactory().CreateCall(0, typeRet, args, pMemGroup, null);
call.mwi = new MethWithInst(mpwi);
switch (ek)
{
case ExpressionKind.EK_EQ:
call.nubLiftKind = NullableCallLiftKind.EqualityOperator;
break;
case ExpressionKind.EK_NE:
call.nubLiftKind = NullableCallLiftKind.InequalityOperator;
break;
default:
call.nubLiftKind = NullableCallLiftKind.Operator;
break;
}
call.castOfNonLiftedResultToLiftedType = mustCast(nonLiftedResult, typeRet, 0);
return call;
}
示例11: BindUDBinopCall
private EXPRCALL BindUDBinopCall(EXPR arg1, EXPR arg2, TypeArray Params, CType typeRet, MethPropWithInst mpwi)
{
arg1 = mustConvert(arg1, Params.Item(0));
arg2 = mustConvert(arg2, Params.Item(1));
EXPRLIST args = GetExprFactory().CreateList(arg1, arg2);
checkUnsafe(arg1.type); // added to the binder so we don't bind to pointer ops
checkUnsafe(arg2.type); // added to the binder so we don't bind to pointer ops
checkUnsafe(typeRet); // added to the binder so we don't bind to pointer ops
EXPRMEMGRP pMemGroup = GetExprFactory().CreateMemGroup(null, mpwi);
EXPRCALL call = GetExprFactory().CreateCall(0, typeRet, args, pMemGroup, null);
call.mwi = new MethWithInst(mpwi);
verifyMethodArgs(call, mpwi.GetType());
return call;
}
示例12: UserDefinedBinaryOperatorCanBeLifted
private bool UserDefinedBinaryOperatorCanBeLifted(ExpressionKind ek, MethodSymbol method, AggregateType ats,
TypeArray Params)
{
if (!Params.Item(0).IsNonNubValType())
{
return false;
}
if (!Params.Item(1).IsNonNubValType())
{
return false;
}
CType typeRet = GetTypes().SubstType(method.RetType, ats);
if (!typeRet.IsNonNubValType())
{
return false;
}
switch (ek)
{
case ExpressionKind.EK_EQ:
case ExpressionKind.EK_NE:
if (!typeRet.isPredefType(PredefinedType.PT_BOOL))
{
return false;
}
if (Params.Item(0) != Params.Item(1))
{
return false;
}
return true;
case ExpressionKind.EK_GT:
case ExpressionKind.EK_GE:
case ExpressionKind.EK_LT:
case ExpressionKind.EK_LE:
if (!typeRet.isPredefType(PredefinedType.PT_BOOL))
{
return false;
}
return true;
default:
return true;
}
}
示例13: ErrAppendParamList
/*
* Create a fill-in string describing a parameter list.
* Does NOT include ()
*/
protected void ErrAppendParamList(TypeArray @params, bool isVarargs, bool isParamArray)
{
if (null == @params)
return;
for (int i = 0; i < @params.size; i++)
{
if (i > 0)
{
ErrAppendString(", ");
}
if (isParamArray && i == @params.size - 1)
{
ErrAppendString("params ");
}
// parameter type name
ErrAppendType(@params.Item(i), null);
}
if (isVarargs)
{
if (@params.size != 0)
{
ErrAppendString(", ");
}
ErrAppendString("...");
}
}
示例14: AreAllTypeArgumentsUnitTypes
public bool AreAllTypeArgumentsUnitTypes(TypeArray typeArray)
{
if (typeArray.Size == 0)
{
return true;
}
for (int i = 0; i < typeArray.size; i++)
{
Debug.Assert(typeArray.Item(i) != null);
if (!typeArray.Item(i).IsOpenTypePlaceholderType())
{
return false;
}
}
return true;
}
示例15: TryGetExpandedParams
protected bool TryGetExpandedParams(TypeArray @params, int count, out TypeArray ppExpandedParams)
{
CType[] prgtype;
if (count < @params.size - 1)
{
// The user has specified less arguments than our parameters, but we still
// need to return our set of types without the param array. This is in the
// case that all the parameters are optional.
prgtype = new CType[@params.size - 1];
@params.CopyItems(0, @params.size - 1, prgtype);
ppExpandedParams = GetGlobalSymbols().AllocParams(@params.size - 1, prgtype);
return true;
}
prgtype = new CType[count];
@params.CopyItems(0, @params.size - 1, prgtype);
CType type = @params.Item(@params.size - 1);
CType elementType = null;
if (!type.IsArrayType())
{
ppExpandedParams = null;
// If we don't have an array sym, we don't have expanded parameters.
return false;
}
// At this point, we have an array sym.
elementType = type.AsArrayType().GetElementType();
for (int itype = @params.size - 1; itype < count; itype++)
{
prgtype[itype] = elementType;
}
ppExpandedParams = GetGlobalSymbols().AllocParams(prgtype);
return true;
}