bool ResolveArgumentExpression (ResolveContext rc, Expression expr)
{
var sn = expr as SimpleName;
if (sn != null) {
Value = sn.Name;
if (rc.Module.Compiler.Settings.Version < LanguageVersion.V_6)
rc.Report.FeatureIsNotAvailable (rc.Module.Compiler, Location, "nameof operator");
var res = sn.LookupNameExpression (rc, MemberLookupRestrictions.IgnoreAmbiguity | MemberLookupRestrictions.NameOfExcluded);
if (sn.HasTypeArguments && res is MethodGroupExpr) {
Error_MethodGroupWithTypeArguments (rc, expr.Location);
}
return true;
}
var ma = expr as MemberAccess;
if (ma != null) {
var lexpr = ma.LeftExpression;
var res = ma.LookupNameExpression (rc, MemberLookupRestrictions.IgnoreAmbiguity);
if (res == null) {
return false;
}
if (rc.Module.Compiler.Settings.Version < LanguageVersion.V_6)
rc.Report.FeatureIsNotAvailable (rc.Module.Compiler, Location, "nameof operator");
if (ma is QualifiedAliasMember) {
rc.Report.Error (8083, loc, "An alias-qualified name is not an expression");
return false;
}
if (!IsLeftExpressionValid (lexpr)) {
rc.Report.Error (8082, lexpr.Location, "An argument to nameof operator cannot include sub-expression");
return false;
}
var mg = res as MethodGroupExpr;
if (mg != null) {
var emg = res as ExtensionMethodGroupExpr;
if (emg != null && !emg.ResolveNameOf (rc, ma)) {
return true;
}
if (!mg.HasAccessibleCandidate (rc)) {
ErrorIsInaccesible (rc, ma.GetSignatureForError (), loc);
}
if (ma.HasTypeArguments) {
Error_MethodGroupWithTypeArguments (rc, ma.Location);
}
}
Value = ma.Name;
return true;
}
rc.Report.Error (8081, loc, "Expression does not have a name");
return false;
}