Click here to Skip to main content
15,891,976 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 10:47
dilkonika15-Apr-15 10:47 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 11:10
professionalSascha Lefèvre15-Apr-15 11:10 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 11:15
dilkonika15-Apr-15 11:15 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 11:22
professionalSascha Lefèvre15-Apr-15 11:22 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 11:53
dilkonika15-Apr-15 11:53 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 12:31
professionalSascha Lefèvre15-Apr-15 12:31 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 12:59
dilkonika15-Apr-15 12:59 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 13:24
professionalSascha Lefèvre15-Apr-15 13:24 
Yes, in the meantime I replicated it - both versions, simplified here:
VB
Dim el = Enumerable.ElementAt(CallByName(MyClass, "Children", CallType.Get), 1)

REM 1
Dim el1 = CType(el, ChildClass)
Dim el1copy = CopyEntity(el1)   REM works. (el1copy is of type ChildClass)

REM 2
Dim el2 = CTypeDynamic(Of ChildClass)(el)
Dim el2copy = CopyEntity(el2)   REM works. (el2copy is of type ChildClass)

REM 3
Dim el3 = CTypeDynamic(el, GetType(ChildClass))
Dim el3copy = CopyEntity(el3)   REM doesn't work. (el3copy is of type Object)
That's basically the same as your code above. And it's still the same as what I'm talking about for the last messages Poke tongue | ;-P

I know you can't use 1 and 2. The reason they work is because the return type of CType(el, ChildClass) and CTypeDynamic(Of ChildClass)(el) is ChildClass. The reason 3 doesn't work is because the return type of CTypeDynamic(el, GetType(ChildClass)) is Object (so it doesn't have anything to do with Type.GetType(..)). So, for 1 and 2 CopyEntity(..) is called for the correct generic type, for 3 it's called with Object as generic type. I don't know if there's a way to make 3 work. I tested the same thing (as 3) in C# and it actually works. Either VB differs there from C# or I just don't know how to do it in VB. I can assure you though that the reflection-approach that I suggested would work. If you want to find out if there is a way to make 3 work I would suggest you post a new question so that someone who knows VB better than me will be more likely to notice.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 13:50
dilkonika15-Apr-15 13:50 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 14:20
professionalSascha Lefèvre15-Apr-15 14:20 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 15:55
dilkonika15-Apr-15 15:55 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre16-Apr-15 7:24
professionalSascha Lefèvre16-Apr-15 7:24 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika16-Apr-15 7:32
dilkonika16-Apr-15 7:32 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre16-Apr-15 8:16
professionalSascha Lefèvre16-Apr-15 8:16 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika16-Apr-15 8:26
dilkonika16-Apr-15 8:26 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre16-Apr-15 8:36
professionalSascha Lefèvre16-Apr-15 8:36 
Questionwhy this code doesn't work ? Pin
dilkonika13-Apr-15 6:20
dilkonika13-Apr-15 6:20 
AnswerRe: why this code doesn't work ? Pin
Sascha Lefèvre13-Apr-15 13:56
professionalSascha Lefèvre13-Apr-15 13:56 
GeneralRe: why this code doesn't work ? Pin
dilkonika13-Apr-15 14:11
dilkonika13-Apr-15 14:11 
GeneralRe: why this code doesn't work ? Pin
Sascha Lefèvre13-Apr-15 15:37
professionalSascha Lefèvre13-Apr-15 15:37 
GeneralRe: why this code doesn't work ? Pin
Sascha Lefèvre14-Apr-15 12:56
professionalSascha Lefèvre14-Apr-15 12:56 
QuestionEntity Framework : Clone an object and only its childs Pin
dilkonika11-Apr-15 17:47
dilkonika11-Apr-15 17:47 
AnswerRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre11-Apr-15 21:02
professionalSascha Lefèvre11-Apr-15 21:02 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
dilkonika12-Apr-15 11:32
dilkonika12-Apr-15 11:32 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre12-Apr-15 11:40
professionalSascha Lefèvre12-Apr-15 11:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.