Property Reflection

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
 
M

Markus Stoeger

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top