By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,699 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,699 IT Pros & Developers. It's quick & easy.

Setting Properties with System.Reflection

P: n/a
Hi all,

I need to set a property on a subclass such as:

Report.ExportOptions.ExportFormatType = ExportFormatType.Excel

AND
Report.ExportOptions.FormatOptions = excelFormatOpts
How would I go about doing this? Do I use the Invoke Member Method?

Thanks.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Yes - you could call the Invoke on the Set method for the property or you
could directly call the SetValue method that's off the PropertyInfo object
which you can retrieve from the type object of your class. There's atleast
one example of SetValue in MSDN which should do what you want.

hope that helps..
Imran.

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
Hi all,

I need to set a property on a subclass such as:

Report.ExportOptions.ExportFormatType = ExportFormatType.Excel

AND
Report.ExportOptions.FormatOptions = excelFormatOpts
How would I go about doing this? Do I use the Invoke Member Method?

Thanks.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #2

P: n/a
"Imran Koradia" <no****@microsoft.com> wrote in
news:u6**************@TK2MSFTNGP11.phx.gbl:
Yes - you could call the Invoke on the Set method for the property or
you could directly call the SetValue method that's off the
PropertyInfo object which you can retrieve from the type object of
your class. There's atleast one example of SetValue in MSDN which
should do what you want.

Yes, but how do I access the subclass properties?

I tried:

Dim pi As System.Reflection.PropertyInfo = objReport.GetType.GetProperty
("ExportFormatOptions")

Which returns the ExportFormatOptions object but I have no access to:
Report.ExportFormatOptions.FormatType or
Report.ExportFormatOptions.ExportOptions
So I tried objReport.GetType.GetProperty
("ExportFormatOptions.FormatType") but that didn't work.

Any ideas?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #3

P: n/a
Get the type object of the subclass (from the instance of the subclass thats
returned via the property ExportFormatOptions) and then get the propertyinfo
object corresponding to its property.

dim pi as system.reflection.propertyinfo = _
objReport.ExportFormatOptions.GetType.GetProperty( "FormatType")

pi.SetValue(objReport.ExportFormatOptions, ExportFormatType.Excel, Nothing)

hope that helps..
Imran.

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"Imran Koradia" <no****@microsoft.com> wrote in
news:u6**************@TK2MSFTNGP11.phx.gbl:
Yes - you could call the Invoke on the Set method for the property or
you could directly call the SetValue method that's off the
PropertyInfo object which you can retrieve from the type object of
your class. There's atleast one example of SetValue in MSDN which
should do what you want.

Yes, but how do I access the subclass properties?

I tried:

Dim pi As System.Reflection.PropertyInfo = objReport.GetType.GetProperty
("ExportFormatOptions")

Which returns the ExportFormatOptions object but I have no access to:
Report.ExportFormatOptions.FormatType or
Report.ExportFormatOptions.ExportOptions
So I tried objReport.GetType.GetProperty
("ExportFormatOptions.FormatType") but that didn't work.

Any ideas?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #4

P: n/a
"Imran Koradia" <no****@microsoft.com> wrote in
news:ec**************@TK2MSFTNGP15.phx.gbl:
Get the type object of the subclass (from the instance of the subclass
thats returned via the property ExportFormatOptions) and then get the
propertyinfo object corresponding to its property.


Ahhh.. thank you. Your example cleared things up. My code is working good
now.

Thanks again!

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.