本文整理汇总了C#中Microsoft.CSharp.RuntimeBinder.Semantics.EXPR.asMEMGRP方法的典型用法代码示例。如果您正苦于以下问题:C# EXPR.asMEMGRP方法的具体用法?C# EXPR.asMEMGRP怎么用?C# EXPR.asMEMGRP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.RuntimeBinder.Semantics.EXPR
的用法示例。
在下文中一共展示了EXPR.asMEMGRP方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MethodGroupReturnTypeInference
////////////////////////////////////////////////////////////////////////////////
private bool MethodGroupReturnTypeInference(EXPR pSource, CType pType)
{
// SPEC: Otherwise, if E is a method group and T is a delegate CType or
// SPEC: expression tree CType with parameter types T1...Tk and return
// SPEC: CType Tb and overload resolution of E with the types T1...Tk
// SPEC: yields a single method with return CType U then a lower-bound
// SPEC: inference is made from U to Tb.
if (!pSource.isMEMGRP())
{
return false;
}
pType = pType.GetDelegateTypeOfPossibleExpression();
if (!pType.isDelegateType())
{
return false;
}
AggregateType pDelegateType = pType.AsAggregateType();
CType pDelegateReturnType = pDelegateType.GetDelegateReturnType(GetSymbolLoader());
if (pDelegateReturnType == null)
{
return false;
}
if (pDelegateReturnType.IsVoidType())
{
return false;
}
// At this point we are in the second phase; we know that all the input types are fixed.
TypeArray pDelegateParameters = GetFixedDelegateParameters(pDelegateType);
if (pDelegateParameters == null)
{
return false;
}
ArgInfos argInfo = new ArgInfos() { carg = pDelegateParameters.size, types = pDelegateParameters, fHasExprs = false, prgexpr = null };
var argsBinder = new ExpressionBinder.GroupToArgsBinder(_binder, 0/* flags */, pSource.asMEMGRP(), argInfo, null, false, pDelegateType);
bool success = argsBinder.Bind(false);
if (!success)
{
return false;
}
MethPropWithInst mwi = argsBinder.GetResultsOfBind().GetBestResult();
CType pMethodReturnType = GetTypeManager().SubstType(mwi.Meth().RetType,
mwi.GetType(), mwi.TypeArgs);
if (pMethodReturnType.IsVoidType())
{
return false;
}
LowerBoundInference(pMethodReturnType, pDelegateReturnType);
return true;
}
示例2: checkLvalue
////////////////////////////////////////////////////////////////////////////////
// A false return means not to process the expr any further - it's totally out
// of place. For example - a method group or an anonymous method.
internal bool checkLvalue(EXPR expr, CheckLvalueKind kind)
{
if (!expr.isOK())
return false;
if (expr.isLvalue())
{
if (expr.isPROP())
{
CheckLvalueProp(expr.asPROP());
}
markFieldAssigned(expr);
return true;
}
switch (expr.kind)
{
case ExpressionKind.EK_PROP:
if (kind == CheckLvalueKind.OutParameter)
{
// passing a property as ref or out
ErrorContext.Error(ErrorCode.ERR_RefProperty);
return true;
}
if (!expr.asPROP().mwtSet)
{
// Assigning to a property without a setter.
// If we have
// bool? b = true; (bool)b = false;
// then this is realized immediately as
// b.Value = false;
// and no ExpressionKind.EK_CAST is generated. We'd rather not give a "you're writing
// to a read-only property" error in the case where the property access
// is not explicit in the source code. Fortunately in this case the
// cast is still hanging around in the parse tree, so we can look for it.
// POSSIBLE ERROR: It would be nice to also give this error for other situations
// POSSIBLE ERROR: in which the user is attempting to assign to a value, such as
// POSSIBLE ERROR: an explicit (bool)b.Value = false;
// POSSIBLE ERROR: Unfortunately we cannot use this trick in that situation because
// POSSIBLE ERROR: we've already discarded the OperatorKind.OP_CAST node. (This is an SyntaxKind.Dot).
// SPEC VIOLATION: More generally:
// SPEC VIOLATION: The spec states that the result of any cast is a value, not a
// SPEC VIOLATION: variable. Unfortunately we do not correctly implement this
// SPEC VIOLATION: and we probably should not start implementing it because this
// SPEC VIOLATION: would be a breaking change. We currently discard "no op" casts
// SPEC VIOLATION: very aggressively rather than generating an ExpressionKind.EK_CAST node.
ErrorContext.Error(ErrorCode.ERR_AssgReadonlyProp, expr.asPROP().pwtSlot);
return true;
}
break;
case ExpressionKind.EK_ARRAYLENGTH:
if (kind == CheckLvalueKind.OutParameter)
{
// passing a property as ref or out
ErrorContext.Error(ErrorCode.ERR_RefProperty);
}
else
{
// Special case, the length property of an array
ErrorContext.Error(ErrorCode.ERR_AssgReadonlyProp, GetSymbolLoader().getPredefinedMembers().GetProperty(PREDEFPROP.PP_ARRAY_LENGTH));
}
return true;
case ExpressionKind.EK_BOUNDLAMBDA:
case ExpressionKind.EK_UNBOUNDLAMBDA:
case ExpressionKind.EK_CONSTANT:
ErrorContext.Error(GetStandardLvalueError(kind));
return false;
case ExpressionKind.EK_MEMGRP:
{
ErrorCode err = (kind == CheckLvalueKind.OutParameter) ? ErrorCode.ERR_RefReadonlyLocalCause : ErrorCode.ERR_AssgReadonlyLocalCause;
ErrorContext.Error(err, expr.asMEMGRP().name, new ErrArgIds(MessageID.MethodGroup));
return false;
}
default:
break;
}
return !TryReportLvalueFailure(expr, kind);
}