当前位置: 首页>>代码示例>>C#>>正文


C# BindValueKind类代码示例

本文整理汇总了C#中BindValueKind的典型用法代码示例。如果您正苦于以下问题:C# BindValueKind类的具体用法?C# BindValueKind怎么用?C# BindValueKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BindValueKind类属于命名空间,在下文中一共展示了BindValueKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckIsValidReceiverForVariable

 private bool CheckIsValidReceiverForVariable(CSharpSyntaxNode node, BoundExpression receiver, BindValueKind kind, DiagnosticBag diagnostics)
 {
     Debug.Assert(receiver != null);
     return Flags.Includes(BinderFlags.ObjectInitializerMember) && receiver.Kind == BoundKind.ImplicitReceiver ||
         CheckIsVariable(node, receiver, kind, true, diagnostics);
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:6,代码来源:Binder_Statements.cs

示例2: CheckValue

        /// <summary>
        /// Check the expression is of the required lvalue and rvalue specified by valueKind.
        /// The method returns the original expression if the expression is of the required
        /// type. Otherwise, an appropriate error is added to the diagnostics bag and the
        /// method returns a BoundBadExpression node. The method returns the original
        /// expression without generating any error if the expression has errors.
        /// </summary>
        private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind, DiagnosticBag diagnostics)
        {
            switch (expr.Kind)
            {
                case BoundKind.PropertyGroup:
                    expr = BindIndexedPropertyAccess((BoundPropertyGroup)expr, mustHaveAllOptionalParameters: false, diagnostics: diagnostics);
                    break;
            }

            bool hasResolutionErrors = false;

            // If this a MethodGroup where an rvalue is not expected or where the caller will not explicitly handle
            // (and resolve) MethodGroups (in short, cases where valueKind != BindValueKind.RValueOrMethodGroup),
            // resolve the MethodGroup here to generate the appropriate errors, otherwise resolution errors (such as
            // "member is inaccessible") will be dropped.
            if (expr.Kind == BoundKind.MethodGroup && valueKind != BindValueKind.RValueOrMethodGroup)
            {
                var methodGroup = (BoundMethodGroup)expr;
                HashSet<DiagnosticInfo> useSiteDiagnostics = null;
                var resolution = this.ResolveMethodGroup(methodGroup, analyzedArguments: null, isMethodGroupConversion: false, useSiteDiagnostics: ref useSiteDiagnostics);
                diagnostics.Add(expr.Syntax, useSiteDiagnostics);
                Symbol otherSymbol = null;
                bool resolvedToMethodGroup = resolution.MethodGroup != null;
                if (!expr.HasAnyErrors) diagnostics.AddRange(resolution.Diagnostics); // Suppress cascading.
                hasResolutionErrors = resolution.HasAnyErrors;
                if (hasResolutionErrors)
                {
                    otherSymbol = resolution.OtherSymbol;
                }
                resolution.Free();

                // It's possible the method group is not a method group at all, but simply a
                // delayed lookup that resolved to a non-method member (perhaps an inaccessible
                // field or property), or nothing at all. In those cases, the member should not be exposed as a
                // method group, not even within a BoundBadExpression. Instead, the
                // BoundBadExpression simply refers to the receiver and the resolved symbol (if any).
                if (!resolvedToMethodGroup)
                {
                    Debug.Assert(methodGroup.ResultKind != LookupResultKind.Viable);
                    BoundNode receiver = methodGroup.ReceiverOpt;
                    if ((object)otherSymbol != null && receiver?.Kind == BoundKind.TypeOrValueExpression)
                    {
                        // Since we're not accessing a method, this can't be a Color Color case, so TypeOrValueExpression should not have been used.
                        // CAVEAT: otherSymbol could be invalid in some way (e.g. inaccessible), in which case we would have fallen back on a
                        // method group lookup (to allow for extension methods), which would have required a TypeOrValueExpression.
                        Debug.Assert(methodGroup.LookupError != null);

                        // Since we have a concrete member in hand, we can resolve the receiver.
                        var typeOrValue = (BoundTypeOrValueExpression)receiver;
                        receiver = otherSymbol.IsStatic
                            ? null // no receiver required
                            : typeOrValue.Data.ValueExpression;
                    }
                    return new BoundBadExpression(
                        expr.Syntax,
                        methodGroup.ResultKind,
                        (object)otherSymbol == null ? ImmutableArray<Symbol>.Empty : ImmutableArray.Create(otherSymbol),
                        receiver == null ? ImmutableArray<BoundNode>.Empty : ImmutableArray.Create(receiver),
                        GetNonMethodMemberType(otherSymbol));
                }
            }

            if (!hasResolutionErrors && CheckValueKind(expr, valueKind, diagnostics) ||
                expr.HasAnyErrors && valueKind == BindValueKind.RValueOrMethodGroup)
            {
                return expr;
            }

            var resultKind = (valueKind == BindValueKind.RValue || valueKind == BindValueKind.RValueOrMethodGroup) ?
                LookupResultKind.NotAValue :
                LookupResultKind.NotAVariable;

            return ToBadExpression(expr, resultKind);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:81,代码来源:Binder_Statements.cs

示例3: ReportReadOnlyError

        private static void ReportReadOnlyError(FieldSymbol field, CSharpSyntaxNode node, BindValueKind kind, bool checkingReceiver, DiagnosticBag diagnostics)
        {
            Debug.Assert((object)field != null);
            Debug.Assert(kind != BindValueKind.RValue);
            Debug.Assert((object)field.Type != null);

            // It's clearer to say that the address can't be taken than to say that the field can't be modified
            // (even though the latter message gives more explanation of why).
            if (kind == BindValueKind.AddressOf)
            {
                Error(diagnostics, ErrorCode.ERR_InvalidAddrOp, node);
                return;
            }

            ErrorCode[] ReadOnlyErrors =
            {
                ErrorCode.ERR_RefReadonly,
                ErrorCode.ERR_AssgReadonly,
                ErrorCode.ERR_RefReadonlyStatic,
                ErrorCode.ERR_AssgReadonlyStatic,
                ErrorCode.ERR_RefReadonly2,
                ErrorCode.ERR_AssgReadonly2,
                ErrorCode.ERR_RefReadonlyStatic2,
                ErrorCode.ERR_AssgReadonlyStatic2
            };
            int index = (checkingReceiver ? 4 : 0) + (field.IsStatic ? 2 : 0) + (kind == BindValueKind.OutParameter ? 0 : 1);
            if (checkingReceiver)
            {
                Error(diagnostics, ReadOnlyErrors[index], node, field);
            }
            else
            {
                Error(diagnostics, ReadOnlyErrors[index], node);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:35,代码来源:Binder_Statements.cs

示例4: CheckIsVariable

        /// <summary>
        /// The purpose of this method is to determine if the expression is classified by the 
        /// specification as a *variable*. If it is not then this code gives an appropriate error message.
        ///
        /// To determine the appropriate error message we need to know two things:
        ///
        /// (1) why do we want to know if this is a variable? Because we are trying to assign it,
        ///     increment it, or pass it by reference?
        ///
        /// (2) Are we trying to determine if the left hand side of a dot is a variable in order
        ///     to determine if the field or property on the right hand side of a dot is assignable?
        /// </summary>
        private bool CheckIsVariable(CSharpSyntaxNode node, BoundExpression expr, BindValueKind kind, bool checkingReceiver, DiagnosticBag diagnostics)
        {
            Debug.Assert(expr != null);
            Debug.Assert(!checkingReceiver || expr.Type.IsValueType);

            // Every expression is classified as one of:
            // 1. a namespace
            // 2. a type
            // 3. an anonymous function
            // 4. a literal
            // 5. an event access
            // 6. a call to a void-returning method
            // 7. a method group
            // 8. a property access
            // 9. an indexer access
            // 10. a variable
            // 11. a value

            // We wish to give an error and return false for all of those except case 10.

            // case 0: We've already reported an error:

            if (expr.HasAnyErrors)
            {
                return false;
            }

            // Case 1: a namespace:
            var ns = expr as BoundNamespaceExpression;
            if (ns != null)
            {
                Error(diagnostics, ErrorCode.ERR_BadSKknown, node, ns.NamespaceSymbol, MessageID.IDS_SK_NAMESPACE.Localize(), MessageID.IDS_SK_VARIABLE.Localize());
                return false;
            }

            // Case 2: a type:
            var type = expr as BoundTypeExpression;
            if (type != null)
            {
                Error(diagnostics, ErrorCode.ERR_BadSKknown, node, type.Type, MessageID.IDS_SK_TYPE.Localize(), MessageID.IDS_SK_VARIABLE.Localize());
                return false;
            }

            // Cases 3, 4, 6:
            if ((expr.Kind == BoundKind.Lambda) ||
                (expr.Kind == BoundKind.UnboundLambda) ||
                (expr.ConstantValue != null) ||
                (expr.Type.GetSpecialTypeSafe() == SpecialType.System_Void))
            {
                Error(diagnostics, GetStandardLvalueError(kind), node);
                return false;
            }

            // Case 5: field-like events are variables

            var eventAccess = expr as BoundEventAccess;
            if (eventAccess != null)
            {
                EventSymbol eventSymbol = eventAccess.EventSymbol;
                if (!eventAccess.IsUsableAsField)
                {
                    Error(diagnostics, GetBadEventUsageDiagnosticInfo(eventSymbol), node);
                    return false;
                }
                else if (eventSymbol.IsWindowsRuntimeEvent)
                {
                    switch (kind)
                    {
                        case BindValueKind.RValue:
                        case BindValueKind.RValueOrMethodGroup:
                            Debug.Assert(false, "Why call CheckIsVariable if you want an RValue?");
                            goto case BindValueKind.Assignment;
                        case BindValueKind.Assignment:
                        case BindValueKind.CompoundAssignment:
                            return true;
                    }

                    // NOTE: Dev11 reports ERR_RefProperty, as if this were a property access (since that's how it will be lowered).
                    // Roslyn reports a new, more specific, error code.
                    Error(diagnostics, kind == BindValueKind.OutParameter ? ErrorCode.ERR_WinRtEventPassedByRef : GetStandardLvalueError(kind), node, eventSymbol);
                    return false;
                }
                else
                {
                    return true;
                }
            }

//.........这里部分代码省略.........
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:101,代码来源:Binder_Statements.cs

示例5: CheckLocalVariable

        // Check to see if a local symbol is to be treated as a variable. Returns true if yes, reports an
        // error and returns false if no.
        private static bool CheckLocalVariable(CSharpSyntaxNode tree, LocalSymbol local, BindValueKind kind, bool checkingReceiver, DiagnosticBag diagnostics)
        {
            Debug.Assert((object)local != null);
            Debug.Assert(kind != BindValueKind.RValue);

            if (local.IsWritable)
            {
                return true;
            }

            MessageID cause;
            if (local.IsForEach)
            {
                cause = MessageID.IDS_FOREACHLOCAL;
            }
            else if (local.IsUsing)
            {
                cause = MessageID.IDS_USINGLOCAL;
            }
            else if (local.IsFixed)
            {
                cause = MessageID.IDS_FIXEDLOCAL;
            }
            else
            {
                Error(diagnostics, GetStandardLvalueError(kind), tree);
                return false;
            }

            if (kind == BindValueKind.AddressOf)
            {
                Error(diagnostics, ErrorCode.ERR_AddrOnReadOnlyLocal, tree);
                return false;
            }

            ErrorCode[] ReadOnlyLocalErrors =
            {
                ErrorCode.ERR_RefReadonlyLocalCause,
                // impossible since readonly locals are never byref, but would be a reasonable error otherwise
                ErrorCode.ERR_RefReadonlyLocalCause,
                ErrorCode.ERR_AssgReadonlyLocalCause,

                ErrorCode.ERR_RefReadonlyLocal2Cause,
                // impossible since readonly locals are never byref, but would be a reasonable error otherwise
                ErrorCode.ERR_RefReadonlyLocal2Cause,
                ErrorCode.ERR_AssgReadonlyLocal2Cause
            };

            int index = (checkingReceiver ? 3 : 0) + (kind == BindValueKind.RefOrOut ? 0 : (kind == BindValueKind.RefReturn ? 1 : 2));

            Error(diagnostics, ReadOnlyLocalErrors[index], tree, local, cause.Localize());

            return false;
        }
开发者ID:abock,项目名称:roslyn,代码行数:56,代码来源:Binder_Statements.cs

示例6: CheckLocalVariable

        // Check to see if a local symbol is to be treated as a variable. Returns true if yes, reports an
        // error and returns false if no.
        private static bool CheckLocalVariable(CSharpSyntaxNode tree, LocalSymbol local, BindValueKind kind, bool checkingReceiver, DiagnosticBag diagnostics)
        {
            Debug.Assert((object)local != null);
            Debug.Assert(kind != BindValueKind.RValue);

            if (local.IsWritable)
            {
                return true;
            }

            MessageID cause = 0;
            if (local.IsForEach)
            {
                cause = MessageID.IDS_FOREACHLOCAL;
            }
            else if (local.IsUsing)
            {
                cause = MessageID.IDS_USINGLOCAL;
            }
            else if (local.IsFixed)
            {
                cause = MessageID.IDS_FIXEDLOCAL;
            }
            else
            {
                Error(diagnostics, GetStandardLvalueError(kind), tree);
                return false;
            }

            if (kind == BindValueKind.AddressOf)
            {
                Error(diagnostics, ErrorCode.ERR_AddrOnReadOnlyLocal, tree);
                return false;
            }

            ErrorCode[] ReadOnlyLocalErrors =
            {
                ErrorCode.ERR_RefReadonlyLocal,
                ErrorCode.ERR_AssgReadonlyLocal,
                ErrorCode.ERR_RefReadonlyLocal,     // Impossible, but if we do run into this situation, this is a sensible error.
                ErrorCode.ERR_AssgReadonlyLocal,    // Also impossible.
                ErrorCode.ERR_RefReadonlyLocalCause,
                ErrorCode.ERR_AssgReadonlyLocalCause,
                ErrorCode.ERR_RefReadonlyLocal2Cause,
                ErrorCode.ERR_AssgReadonlyLocal2Cause
            };

            int index = (cause != 0 ? 4 : 0) + (checkingReceiver ? 2 : 0) + (kind == BindValueKind.OutParameter ? 0 : 1);

            Debug.Assert(index != 2 && index != 3);
            // There is no way that we can have no cause AND a read-only local nested in a struct with a
            // writable field. What would make the local read-only if not one of the causes above?  (Const
            // locals may not be structs, so we would already have errored out in that scenario.)

            if (cause != 0)
            {
                Error(diagnostics, ReadOnlyLocalErrors[index], tree, local, cause.Localize());
            }
            else
            {
                Error(diagnostics, ReadOnlyLocalErrors[index], tree, local);
            }

            return false;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:67,代码来源:Binder_Statements.cs

示例7: GetThisLvalueError

 static private ErrorCode GetThisLvalueError(BindValueKind kind)
 {
     switch (kind)
     {
         default:
             throw ExceptionUtilities.UnexpectedValue(kind);
         case BindValueKind.CompoundAssignment:
         case BindValueKind.Assignment:
             return ErrorCode.ERR_AssgReadonlyLocal;
         case BindValueKind.OutParameter:
             return ErrorCode.ERR_RefReadonlyLocal;
         case BindValueKind.AddressOf:
             return ErrorCode.ERR_AddrOnReadOnlyLocal;
         case BindValueKind.IncrementDecrement:
             return ErrorCode.ERR_IncrementLvalueExpected;
     }
 }
开发者ID:jeffanders,项目名称:roslyn,代码行数:17,代码来源:Binder_Statements.cs

示例8: CheckPropertyValueKind

        private bool CheckPropertyValueKind(BoundExpression expr, BindValueKind valueKind, DiagnosticBag diagnostics)
        {
            // SPEC: If the left operand is a property or indexer access, the property or indexer must
            // SPEC: have a set accessor. If this is not the case, a compile-time error occurs.

            // Addendum: Assignment is also allowed for get-only autoprops in their constructor

            BoundExpression receiver;
            CSharpSyntaxNode propertySyntax;
            var propertySymbol = GetPropertySymbol(expr, out receiver, out propertySyntax);

            Debug.Assert((object)propertySymbol != null);
            Debug.Assert(propertySyntax != null);

            var node = expr.Syntax;

            if (valueKind == BindValueKind.OutParameter || valueKind == BindValueKind.AddressOf)
            {
                // We know the outcome, we just want the diagnostics.
                bool isVariable = CheckIsVariable(node, expr, valueKind, false, diagnostics);
                Debug.Assert(!isVariable, "Properties are never variables");
                return false;
            }

            if (RequiresSettingValue(valueKind))
            {
                var setMethod = propertySymbol.GetOwnOrInheritedSetMethod();

                if ((object)setMethod == null)
                {
                    var containing = this.ContainingMemberOrLambda;
                    if (!AccessingAutopropertyFromConstructor(receiver, propertySymbol, containing))
                    {
                        Error(diagnostics, ErrorCode.ERR_AssgReadonlyProp, node, propertySymbol);
                        return false;
                    }
                }
                else if (receiver?.Kind == BoundKind.BaseReference && setMethod.IsAbstract)
                {
                    Error(diagnostics, ErrorCode.ERR_AbstractBaseCall, node, propertySymbol);
                    return false;
                }
                else if (!object.Equals(setMethod.GetUseSiteDiagnostic(), propertySymbol.GetUseSiteDiagnostic()) && ReportUseSiteDiagnostics(setMethod, diagnostics, propertySyntax))
                {
                    return false;
                }
                else
                {
                    var accessThroughType = this.GetAccessThroughType(receiver);
                    bool failedThroughTypeCheck;
                    HashSet<DiagnosticInfo> useSiteDiagnostics = null;
                    bool isAccessible = this.IsAccessible(setMethod, accessThroughType, out failedThroughTypeCheck, ref useSiteDiagnostics);
                    diagnostics.Add(node, useSiteDiagnostics);

                    if (!isAccessible)
                    {
                        if (failedThroughTypeCheck)
                        {
                            Error(diagnostics, ErrorCode.ERR_BadProtectedAccess, node, propertySymbol, accessThroughType, this.ContainingType);
                        }
                        else
                        {
                            Error(diagnostics, ErrorCode.ERR_InaccessibleSetter, node, propertySymbol);
                        }
                        return false;
                    }

                    ReportDiagnosticsIfObsolete(diagnostics, setMethod, node, receiver?.Kind == BoundKind.BaseReference);

                    if (RequiresVariableReceiver(receiver, setMethod))
                    {
                        if (!CheckIsValidReceiverForVariable(node, receiver, BindValueKind.Assignment, diagnostics))
                        {
                            return false;
                        }
                    }
                }
            }

            if (RequiresGettingValue(valueKind))
            {
                var getMethod = propertySymbol.GetOwnOrInheritedGetMethod();

                if ((object)getMethod == null)
                {
                    Error(diagnostics, ErrorCode.ERR_PropertyLacksGet, node, propertySymbol);
                    return false;
                }
                else if (receiver?.Kind == BoundKind.BaseReference && getMethod.IsAbstract)
                {
                    Error(diagnostics, ErrorCode.ERR_AbstractBaseCall, node, propertySymbol);
                    return false;
                }
                else if (!object.Equals(getMethod.GetUseSiteDiagnostic(), propertySymbol.GetUseSiteDiagnostic()) && ReportUseSiteDiagnostics(getMethod, diagnostics, propertySyntax))
                {
                    return false;
                }
                else
                {
                    var accessThroughType = this.GetAccessThroughType(receiver);
//.........这里部分代码省略.........
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:101,代码来源:Binder_Statements.cs

示例9: IsInitializerRefKindValid

        protected static bool IsInitializerRefKindValid(
            EqualsValueClauseSyntax initializer,
            CSharpSyntaxNode node,
            RefKind variableRefKind,
            DiagnosticBag diagnostics,
            out BindValueKind valueKind,
            out ExpressionSyntax value)
        {
            RefKind expressionRefKind = RefKind.None;
            value = initializer?.Value.SkipRef(out expressionRefKind);
            if (variableRefKind == RefKind.None)
            {
                valueKind = BindValueKind.RValue;
                if (expressionRefKind == RefKind.Ref)
                {
                    Error(diagnostics, ErrorCode.ERR_InitializeByValueVariableWithReference, node);
                    return false;
                }
            }
            else
            {
                valueKind = BindValueKind.RefOrOut;
                if (initializer == null)
                {
                    Error(diagnostics, ErrorCode.ERR_ByReferenceVariableMustBeInitialized, node);
                    return false;
                }
                else if (expressionRefKind != RefKind.Ref)
                {
                    Error(diagnostics, ErrorCode.ERR_InitializeByReferenceVariableWithValue, node);
                    return false;
                }
            }

            return true;
        }
开发者ID:abock,项目名称:roslyn,代码行数:36,代码来源:Binder_Statements.cs

示例10: GetRangeLvalueError

 private static ErrorCode GetRangeLvalueError(BindValueKind kind)
 {
     switch (kind)
     {
         case BindValueKind.Assignment:
         case BindValueKind.CompoundAssignment:
         case BindValueKind.IncrementDecrement:
             return ErrorCode.ERR_QueryRangeVariableReadOnly;
         case BindValueKind.OutParameter:
             return ErrorCode.ERR_QueryOutRefRangeVariable;
         case BindValueKind.AddressOf:
             return ErrorCode.ERR_InvalidAddrOp;
         default:
             throw ExceptionUtilities.UnexpectedValue(kind);
     }
 }
开发者ID:jeffanders,项目名称:roslyn,代码行数:16,代码来源:Binder_Statements.cs

示例11: BindInferredVariableInitializer

        // The location where the error is reported might not be the initializer.
        protected BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnostics, ExpressionSyntax initializer, BindValueKind valueKind,
            CSharpSyntaxNode errorSyntax)
        {
            if (initializer == null)
            {
                if (!errorSyntax.HasErrors)
                {
                    Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableWithNoInitializer, errorSyntax);
                }

                return null;
            }

            if (initializer.Kind() == SyntaxKind.ArrayInitializerExpression)
            {
                return BindUnexpectedArrayInitializer((InitializerExpressionSyntax)initializer,
                    diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedArrayInitializer, errorSyntax);
            }

            BoundExpression expression = BindValue(initializer, diagnostics, valueKind);

            // Certain expressions (null literals, method groups and anonymous functions) have no type of 
            // their own and therefore cannot be the initializer of an implicitly typed local.
            if (!expression.HasAnyErrors && !expression.HasExpressionType())
            {
                // Cannot assign {0} to an implicitly-typed local variable
                Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, errorSyntax, expression.Display);
            }

            return expression;
        }
开发者ID:abock,项目名称:roslyn,代码行数:32,代码来源:Binder_Statements.cs

示例12: BindPossibleArrayInitializer

        private BoundExpression BindPossibleArrayInitializer(
            ExpressionSyntax node,
            TypeSymbol destinationType,
            BindValueKind valueKind,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(node != null);

            if (node.Kind() != SyntaxKind.ArrayInitializerExpression)
            {
                return BindValue(node, diagnostics, valueKind);
            }

            if (destinationType.Kind == SymbolKind.ArrayType)
            {
                return BindArrayCreationWithInitializer(diagnostics, null,
                    (InitializerExpressionSyntax)node, (ArrayTypeSymbol)destinationType,
                    ImmutableArray<BoundExpression>.Empty);
            }

            return BindUnexpectedArrayInitializer((InitializerExpressionSyntax)node, diagnostics, ErrorCode.ERR_ArrayInitToNonArrayType);
        }
开发者ID:abock,项目名称:roslyn,代码行数:22,代码来源:Binder_Statements.cs

示例13: CheckIsCallVariable

        private bool CheckIsCallVariable(BoundCall call, CSharpSyntaxNode node, BindValueKind kind, bool checkingReceiver, DiagnosticBag diagnostics)
        {
            // A call can only be a variable if it returns by reference. If this is the case,
            // whether or not it is a valid variable depends on whether or not the call is the
            // RHS of a return or an assign by reference:
            // - If call is used in a context demanding ref-returnable reference all of its ref
            //   inputs must be ref-returnable

            var methodSymbol = call.Method;
            if (methodSymbol.RefKind != RefKind.None)
            {
                if (kind == BindValueKind.RefReturn)
                {
                    var args = call.Arguments;
                    var argRefKinds = call.ArgumentRefKindsOpt;
                    if (!argRefKinds.IsDefault)
                    {
                        for (var i = 0; i < args.Length; i++)
                        {
                            if (argRefKinds[i] != RefKind.None && !CheckIsVariable(args[i].Syntax, args[i], kind, false, diagnostics))
                            {
                                var errorCode = checkingReceiver ? ErrorCode.ERR_RefReturnCall2 : ErrorCode.ERR_RefReturnCall;
                                var parameterIndex = call.ArgsToParamsOpt.IsDefault ? i : call.ArgsToParamsOpt[i];
                                var parameterName = methodSymbol.Parameters[parameterIndex].Name;
                                Error(diagnostics, errorCode, call.Syntax, methodSymbol, parameterName);
                                return false;
                            }
                        }
                    }
                }

                return true;
            }

            if (checkingReceiver)
            {
                // Error is associated with expression, not node which may be distinct.
                Error(diagnostics, ErrorCode.ERR_ReturnNotLValue, call.Syntax, methodSymbol);
            }
            else
            {
                Error(diagnostics, GetStandardLvalueError(kind), node);
            }

            return false;
        }
开发者ID:abock,项目名称:roslyn,代码行数:46,代码来源:Binder_Statements.cs

示例14: CheckValueKind

        internal bool CheckValueKind(BoundExpression expr, BindValueKind valueKind, DiagnosticBag diagnostics)
        {
            if (expr.HasAnyErrors)
            {
                return false;
            }

            switch (expr.Kind)
            {
                case BoundKind.PropertyAccess:
                case BoundKind.IndexerAccess:
                    return CheckPropertyValueKind(expr, valueKind, diagnostics);
                case BoundKind.EventAccess:
                    return CheckEventValueKind((BoundEventAccess)expr, valueKind, diagnostics);
                case BoundKind.DynamicMemberAccess:
                case BoundKind.DynamicIndexerAccess:
                    return true;
                default:
                    {
                        if (RequiresSettingValue(valueKind))
                        {
                            if (!CheckIsVariable(expr.Syntax, expr, valueKind, false, diagnostics))
                            {
                                return false;
                            }
                        }

                        if (RequiresGettingValue(valueKind))
                        {
                            if (!CheckNotNamespaceOrType(expr, diagnostics))
                            {
                                return false;
                            }
                        }

                        return true;
                    }
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:39,代码来源:Binder_Statements.cs

示例15: GetThisLvalueError

 static private ErrorCode GetThisLvalueError(BindValueKind kind)
 {
     switch (kind)
     {
         default:
             Debug.Assert(false, "bad BindValueKind");
             goto case BindValueKind.Assignment;
         case BindValueKind.CompoundAssignment:
         case BindValueKind.Assignment:
             return ErrorCode.ERR_AssgReadonlyLocal;
         case BindValueKind.OutParameter:
             return ErrorCode.ERR_RefReadonlyLocal;
         case BindValueKind.AddressOf:
             return ErrorCode.ERR_AddrOnReadOnlyLocal;
         case BindValueKind.IncrementDecrement:
             return ErrorCode.ERR_IncrementLvalueExpected;
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:18,代码来源:Binder_Statements.cs


注:本文中的BindValueKind类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。