示例#1
0
        private BoundEqualsValue BindEqualsValue(
            Binder binder,
            EqualsValueClauseSyntax equalsValue,
            BindingDiagnosticBag diagnostics
            )
        {
            switch (this.MemberSymbol.Kind)
            {
            case SymbolKind.Field:
            {
                var field     = (FieldSymbol)this.MemberSymbol;
                var enumField = field as SourceEnumConstantSymbol;
                if ((object)enumField != null)
                {
                    return(binder.BindEnumConstantInitializer(
                               enumField,
                               equalsValue,
                               diagnostics
                               ));
                }
                else
                {
                    return(binder.BindFieldInitializer(field, equalsValue, diagnostics));
                }
            }

            case SymbolKind.Property:
            {
                var property = (SourcePropertySymbol)this.MemberSymbol;
                BoundFieldEqualsValue result = binder.BindFieldInitializer(
                    property.BackingField,
                    equalsValue,
                    diagnostics
                    );
                return(new BoundPropertyEqualsValue(
                           result.Syntax,
                           property,
                           result.Locals,
                           result.Value
                           ));
            }

            case SymbolKind.Parameter:
            {
                var parameter = (ParameterSymbol)this.MemberSymbol;
                return(binder.BindParameterDefaultValue(
                           equalsValue,
                           parameter,
                           diagnostics,
                           out _
                           ));
            }

            default:
                throw ExceptionUtilities.UnexpectedValue(this.MemberSymbol.Kind);
            }
        }