all groups > vb.net upgrade > july 2005 >
You're in the

vb.net upgrade

group:

Reflecing on Friend Properties...


Reflecing on Friend Properties... MstrControl
7/15/2005 12:47:08 PM
vb.net upgrade:
Greetings All...

I'm creating a BaseClass that will connect to a database and retrieve
the all the properties values from it.

So far so good. All the inherited classes retrieve it values from the
database... IF the properties are PUBLIC.

I'm using Reflection GetProperties and GetMemebers to retrieve the list
of properties of each class.

But in some classes I need that the BaseClass being able to see the
Friend properties.

Just to be on the same page... All classes are in a single Assembly,
so, it SHOULD work.

Does anyone know how to retrieve a list of Frined properties?

I know it's possible because the Class Viewer shows everything... I
just don't know how yet.

Regards,

Paulo
Re: Reflecing on Friend Properties... Jon Skeet [C# MVP]
7/16/2005 12:00:00 AM
[quoted text, click to view]

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: Reflecing on Friend Properties... Herfried K. Wagner [MVP]
7/16/2005 12:00:00 AM
Jon,

"Jon Skeet [C# MVP]" <skeet@pobox.com> schrieb:
[quoted text, click to view]

My bad -- it seems that there was something wrong in my code. The code
below demonstrates how to determine the non-public properties including the
friend ones:

\\\
Dim f As New Foo
Dim Properties() As PropertyInfo = _
f.GetType().GetProperties( _
BindingFlags.Instance Or _
BindingFlags.NonPublic _
)
For Each pi As PropertyInfo in Properties
MsgBox(p.Name)
Next pi
..
..
..
Public Class Foo
Private m_Bar As String

Friend Property Bar() As String
Get
Return m_Bar
End Get
Set(ByVal Value As String)
m_Bar = Value
End Set
End Property
End Class
///

- or -

\\\
Dim f As New Foo
MsgBox( _
f.GetType().GetProperty( _
"Bar", _
BindingFlags.Instance Or BindingFlags.NonPublic _
).Name _
)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Re: Reflecing on Friend Properties... Jon Skeet [C# MVP]
7/16/2005 7:26:32 AM
[quoted text, click to view]

Call the overload of GetProperties which takes a BindingFlags
parameter, and include BindingFlags.NonPublic.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: Reflecing on Friend Properties... Herfried K. Wagner [MVP]
7/16/2005 10:33:01 AM
Jon,

"Jon Skeet [C# MVP]" <skeet@pobox.com> schrieb:
[quoted text, click to view]

Mhm... I only made a quick check with 'GetProperty' +
'BindingFlags.NonPublic', but this didn't return the property for me...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
AddThis Social Bookmark Button