|
-
Sep 6th, 2007, 12:48 AM
#1
Thread Starter
Fanatic Member
[RESOLVED, can't be done] Select Case with reference types
I was under the impression that it would be possible to do a select case on reference types themselves (not just their properties.) The comparator for reference types is 'is', not '=', but Case Is GetType(Splitter) automatically inserts the '='. It doesn't like Case Is Is GetType(Splitter) either.
Any ideas on how to do this, preferably with select case, as I will be adding more than just two types later on.
vb Code:
For Each current As Control In form.Controls
Select Case current.GetType
Case Is = GetType(Splitter)
'some code
Case Is = GetType(ColumnHeader)
'more code
Case Else
'nothing
End Select
Next
Last edited by agent; Sep 6th, 2007 at 09:28 PM.
-
Sep 6th, 2007, 01:40 AM
#2
Re: Select Case with reference types
Select Case can only be use where the '=' opertaor is defined for the type of the expression and the type of the cases. You can do this:
vb.net Code:
Select Case True
Case TypeOf current Is Splitter
Case TyoeOf current is ColumnHeader
Case Else
End Select
but that gains you nothing over using If...ElseIf statements.
-
Sep 6th, 2007, 02:37 AM
#3
Re: Select Case with reference types
Code:
Select Case current.GetType().ToString()
Case "WhateverNamespaceName.Splitter"
' ...
Case "WhateverNamespaceName.ColumnHeader"
' ...
End Select
However, I recommend that you use the If...ElseIf method instead. Why? Refactoring won't change class names in strings, and you'll end up with code that builds but doesn't work.
-
Sep 6th, 2007, 09:28 PM
#4
Thread Starter
Fanatic Member
Re: Select Case with reference types
Whoops, ColumnHeader isn't derrived from Control.
This is what I'm using:
vb Code:
For Each current As Control In form.Controls
If current.GetType Is GetType(Splitter) Then
'Some code
ElseIf current.GetType Is GetType(ListView) Then
Dim tmp As ListView = current
For Each clm As ColumnHeader In tmp.Columns
'Some more code
Next
End If
Next
-
Sep 6th, 2007, 09:40 PM
#5
Re: [RESOLVED, can't be done] Select Case with reference types
You shouldn't be calling GetType more than once:
vb.net Code:
Dim currentType As Type
For Each current As Control In form.Controls
currentType = current.GetType()
If currentType Is GetType(Splitter) Then
ElseIf currentType Is GetType(ColumnHeader) Then
End If
Next current
-
Sep 6th, 2007, 10:55 PM
#6
Thread Starter
Fanatic Member
Re: [RESOLVED, can't be done] Select Case with reference types
Thanks... didn't think about that one... I'll fix it in a few minutes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|