private static bool IsAssignableExpression(Binder binder, BoundExpression expression) { // NOTE: Surprisingly, binder.CheckValueKind will return true (!) for readonly fields // in contexts where they cannot be assigned - it simply reports a diagnostic. // Presumably, this is done to avoid producing a confusing error message about the // field not being an lvalue. var diagnostics = DiagnosticBag.GetInstance(); var result = binder.CheckValueKind(expression, Binder.BindValueKind.Assignment, diagnostics) && !diagnostics.HasAnyErrors(); diagnostics.Free(); return result; }