The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Reflecting on properties and fields (literally and figuratively)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jeff Key

Posts: 481
Nickname: jeffreykey
Registered: Nov, 2003

Jeff Key is legally sane, but questionably competent.
Reflecting on properties and fields (literally and figuratively) Posted: Feb 4, 2004 11:51 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jeff Key.
Original Post: Reflecting on properties and fields (literally and figuratively)
Feed Title: Jeff Key
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/jkey/Rss.aspx
Feed Description: Topics revolve around .NET and the Windows platform.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jeff Key
Latest Posts From Jeff Key

Advertisement

The honorable Mr. Fowler today posted that he's +1 for .NET properties and -1 for reflection's differentiation between the two.  His complain is that while you can access both on an object with the same syntax you cannot access them with the same code via reflection.

This is true, but getting around it is simple enough, even if you've already written reflection code to handle fields.  The answer: refactor it!  Extract your getter/setter code to their own methods and create an additional overload that handles properties.  You can get all fields and properties via GetMembers by using the GetFields and GetProperties BindingFlags in addition to whatever criteria you have.  While iterating through these members, simply pass your MemberInfo to one of the overloaded methods and you're set.

Read: Reflecting on properties and fields (literally and figuratively)

Topic: Missed my Blogoversary Previous Topic   Next Topic Topic: Software that makes your life with a Creative Zen easier

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use