Have you tried using the BaseType property of the type you currently
have?  That give you the ability to get the base type, but then the
question is, "how do you know when to stop iterating up".  I go until I
hit null (which will be the case when your current type is Object), but
some people may say that will be too big of a performance hit if you
have a deep hierarchy.

Stokes

-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Malcolm Young
Sent: Monday, August 22, 2005 4:48 PM
To: [email protected]
Subject: [ADVANCED-DOTNET] Using Reflection to Obtain Private Members of
Base Classes

Hi All,

We have developed an OR mapping tool in house. Fields and properties are
marked up with attributes that describe the mappings. In order to
preserve encapsulation, these fields may be private. When it's time to
hydrate or persist the object, the mappings are used to gain access to
each field.

This works fine except when inheritance comes in to the picture. Classes
that derive from other classes obviously can't reflect on their bases
private members. If the persistence code was manually coded this
wouldn't be a problem as we could just call a virtual method that could
call it's base however I am trying to perform the hydration,
serialisation on the basis of metadata.

So far we ahve worked around this by making all the members of the base
class protected but it's a pretty crappy solution. So I guess my
question is: 'Can I use reflection to gain a reference to a base classes
private members?'.

Thanks Guys,

mal

===================================
This list is hosted by DevelopMentor  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to