Property Reflection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've never messed with Reflection at all, so I am unsure of where to start.
All of the documentation/articles I've found aren't helping much, or are too
complex for what I need.

All I need to do is take an assembly that only contains one type and
retrieve the value of a property (that has a known name).

I've tried using something like this that I found in some documentation:

Dim x As [Assembly] = [Assembly].LoadFile("someAsm.dll")

Dim t As Type = x.GetTypes(0)
Dim m As PropertyInfo = t.GetProperty("propName")
Dim obj As Object = Activator.CreateInstance(t)
Dim i As Integer = m.GetValue(<ok what is supposed to go here?>)

I'm not sure what the getvalue method is supposed to take as arguments. Am I
even doing this right?

Thanks
 
Devin said:
Dim x As [Assembly] = [Assembly].LoadFile("someAsm.dll")

Dim t As Type = x.GetTypes(0)
Dim m As PropertyInfo = t.GetProperty("propName")
Dim obj As Object = Activator.CreateInstance(t)
Dim i As Integer = m.GetValue(<ok what is supposed to go here?>)

I'm not sure what the getvalue method is supposed to take as arguments.

Give it the object that contains the property you want to get. In your
case thats "obj".

Max
 
right, that makes sense now that it's obvious. It's been a long day.

Well, anyway, I just decided to use an interface and some weird stuff
internal to the class in the assembly so that I can get values out. I had
wanted to use reflection because I wouldn't be able to know everything about
all of the properties until runtime.

Thank for you time though



Markus Stoeger said:
Devin said:
Dim x As [Assembly] = [Assembly].LoadFile("someAsm.dll")

Dim t As Type = x.GetTypes(0)
Dim m As PropertyInfo = t.GetProperty("propName")
Dim obj As Object = Activator.CreateInstance(t)
Dim i As Integer = m.GetValue(<ok what is supposed to go here?>)

I'm not sure what the getvalue method is supposed to take as arguments.

Give it the object that contains the property you want to get. In your
case thats "obj".

Max
 
Back
Top