Click here to Skip to main content
15,911,327 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Extended ASCII with UTF-8 in VB.NET Pin
Richard MacCutchan15-Apr-15 21:30
mveRichard MacCutchan15-Apr-15 21:30 
QuestionHashSet(Of T) - how can I get elements by position number ? Pin
dilkonika14-Apr-15 12:20
dilkonika14-Apr-15 12:20 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
PIEBALDconsult14-Apr-15 12:55
mvePIEBALDconsult14-Apr-15 12:55 
AnswerRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre14-Apr-15 13:23
professionalSascha Lefèvre14-Apr-15 13:23 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika14-Apr-15 16:42
dilkonika14-Apr-15 16:42 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre14-Apr-15 22:57
professionalSascha Lefèvre14-Apr-15 22:57 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 6:34
dilkonika15-Apr-15 6:34 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 7:19
professionalSascha Lefèvre15-Apr-15 7:19 
This is a bit speculation because I don't have a lot of experience with dynamic typing. But I'm almost sure about it:
VB
Dim element = Enumerable.ElementAt(CallByName(MyObject, "Child1", CallType.Get), k)
REM "element" actually is of the type the elements of Child1 have
REM but at this point it's treated as type Object

REM so this generic function is called for the generic type Object
Public Function CopyEntity(Of T As {Class, New})(ctx As MyEntities, entity As T, ...) As T
    REM so "clone" actually is created as just an Object and not of the same type as "element" / "entity"
    Dim clone As New T()
    REM and the type Object of course isn't a valid entity-type in your context
    Dim en = ctx.Entry(clone)

Your options:

1) An ugly if-else-cascade for all potential types of entities where you test for the actual type of the entity and call CopyEntity(..) with an according cast.

2) Reflection. C#-sample here (last time you said you could read it - otherwise please ask):
C#
// CEClass    : class that contains the function CopyEntity
// CEInstance : an instance of CEClass

MethodInfo mi = typeof(CEClass).GetMethod("CopyEntity");
mi = mi.MakeGenericMethod(typeof(MyEntities), element.GetType(), typeof(bool));
// you could cache "mi"

object clone = mi.Invoke(CEInstance, new object[] {context, element, false});

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 7:34
dilkonika15-Apr-15 7:34 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 7:54
professionalSascha Lefèvre15-Apr-15 7:54 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
dilkonika15-Apr-15 8:23
dilkonika15-Apr-15 8:23 
GeneralRe: HashSet(Of T) - how can I get elements by position number ? Pin
Sascha Lefèvre15-Apr-15 9:29
professionalSascha Lefèvre15-Apr-15 9:29 
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 
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 

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.