Private Function GetControlValue()

in vsintegration/src/FSharp.ProjectSystem.PropertyPages/PropertyPages/PropertyControlData.vb [1248:1350]


        Private Function GetControlValue(ByVal control As Control, ByVal _TypeConverter As TypeConverter) As Object

            Dim StringText As String
            Dim value As Object = Nothing
            Dim convertedvalue As Object

            Debug.Assert(MultiValueGetCallback Is Nothing, "GetControlValue doesn't support MultiValueGetCallback")

            If Me.GetCallback IsNot Nothing Then
                If Me.GetCallback(Me.FormControl, Me.PropDesc, value) Then
                    Return value
                End If
            End If

            value = Nothing

            If TypeOf control Is System.Windows.Forms.TextBox Then
                StringText = Trim(DirectCast(control, System.Windows.Forms.TextBox).Text)
                

                Debug.Assert(Not ExtendedPropertiesObjects Is Nothing, "ExtendedPropertiesObjects was null!")
                If ExtendedPropertiesObjects IsNot Nothing Then
                    If ExtendedPropertiesObjects.Length > 1 _
                    AndAlso TypeOf InitialValue Is String _
                    AndAlso Not Me.IsDirty _
                    AndAlso Not Me.IsCommonProperty _
                    Then
                        
                        
                        value = PropertyControlData.Indeterminate
                    Else
                        value = StringText
                    End If
                Else
                    
                    value = StringText
                End If

            ElseIf TypeOf control Is System.Windows.Forms.ComboBox Then
                Dim cbx As ComboBox = DirectCast(control, System.Windows.Forms.ComboBox)

                If cbx.DropDownStyle = ComboBoxStyle.DropDownList Then
                    If cbx.SelectedIndex = -1 Then
                        value = PropertyControlData.Indeterminate
                    Else
                        value = cbx.SelectedItem
                    End If
                Else
                    StringText = Trim(cbx.Text)
                    Debug.Assert(ExtendedPropertiesObjects IsNot Nothing, "ExtendedPropertiesObjects was null!")
                    If ExtendedPropertiesObjects IsNot Nothing Then
                        If ExtendedPropertiesObjects.Length > 1 _
                        AndAlso TypeOf InitialValue Is String _
                        AndAlso Not Me.IsDirty _
                        AndAlso Not Me.IsCommonProperty _
                        Then
                            
                            
                            value = PropertyControlData.Indeterminate
                        Else
                            value = StringText
                        End If
                    Else
                        
                        value = StringText
                    End If
                End If

            ElseIf TypeOf control Is System.Windows.Forms.CheckBox Then
                Dim chk As CheckBox = DirectCast(control, System.Windows.Forms.CheckBox)

                If chk.CheckState = CheckState.Indeterminate Then
                    value = PropertyControlData.Indeterminate
                Else
                    value = chk.Checked
                End If

            ElseIf TypeOf control Is System.Windows.Forms.Label Then
                
                Debug.Assert(False, "Labels should be ReadOnly and never changed")

            ElseIf control Is Nothing Then
                Debug.Fail("PropPageUserControlBase.InitPage(): control is Nothing")

            End If

            If (value IsNot Nothing) And (Not value Is PropertyControlData.Indeterminate) Then
                If (_TypeConverter IsNot Nothing) Then
                    If _TypeConverter.CanConvertFrom(Nothing, value.GetType()) Then
                        
                        
                        
                        
                        If _TypeConverter.IsValid(value) Then
                            convertedvalue = _TypeConverter.ConvertFrom(value)
                            value = convertedvalue
                        End If
                    End If
                End If
            End If
            Return value

        End Function