setting a property value using reflection

Posted on 2008-11-19
Last Modified: 2012-05-05
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

Question by:scm0sml
    LVL 12

    Accepted Solution

    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.


    Author Closing Comment

    good man.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now