Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

setting a property value using reflection

If the code below gets a property by constructing the property name how would i set it?

say i want to set the property availabilityMonth.Day07 = 12 for e.g?

how would i do that?

im trying something like:
dayAvailability.SetValue(_availabilityMonth, 2, Reflection.BindingFlags.SetProperty)

but not getting very far?
Dim dayAvailability As Reflection.PropertyInfo = Nothing
 
 dayAvailability = _availabilityMonth.GetType.GetProperty("Day" + monthDay.ToString())

Open in new window

0
scm0sml
Asked:
scm0sml
1 Solution
 
omegaomegaDeveloperCommented:
Hello, scm0sml,

It looks close.  Try replacing Reflection.BindingFlags.SetProperty with Nothing.  I.e. try:

    dayAvailability.SetValue(_availabilityMonth, 12, Nothing)

(I've also changed the second parameter, 2, to 12 to correspond better with your example.

Cheers,
Randy
0
 
scm0smlAuthor Commented:
good man.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now