![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've using Reflection to get a value from a property in a class and I needed to modify it to allow Friend properties to be included: PropertyInfo = Me.GetType.GetProperty(Name, BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance) Now I understand what the Public & NonPublic flags are doing but without the Instance flag as well, it doesn't work. Can anyone please explain why adding Instance makes it work? MSDN is a bit vague about what the instance flag does (to me anyway): "Specifies that instance members are to be included in the search" I think I know what an instance is but maybe not! |
#3
| |||
| |||
|
|
Instance members are members that aren't static. Static members are declared (in C#) with the 'static' keyword, I think it's 'Shared' in VB. |
#4
| |||
| |||
|
|
"Rob Nicholson" <rob.nicholson (AT) nospam_unforgettable (DOT) com> wrote: I've using Reflection to get a value from a property in a class and I needed to modify it to allow Friend properties to be included: PropertyInfo = Me.GetType.GetProperty(Name, BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance) |
|
Now I understand what the Public & NonPublic flags are doing but without the Instance flag as well, it doesn't work. Can anyone please explain why adding Instance makes it work? MSDN is a bit vague about what the instance flag does (to me anyway): "Specifies that instance members are to be included in the search" I think I know what an instance is but maybe not! Instance members are members that aren't static. Static members are declared (in C#) with the 'static' keyword, I think it's 'Shared' in VB. Instance members are members which need to be applied to an instance. For example, the Length property of System.String is an instance property. You can't simply call 'String.Length', because it isn't a static property, it's an instance property. On the other hand, the 'String.Empty' field is a static field, and can't be applied to an instance. You can't use: "foo".Empty as an expression, since the Empty field is static and can't be applied to an instance. -- Barry |
#5
| |||
| |||
|
|
Instance members are members that aren't static. Static members are declared (in C#) with the 'static' keyword, I think it's 'Shared' in VB. Okay, I understand that now but why does applying the Instance flag to GetProperty effect allow you to use: |
|
Friend ReadOnly Property SomeProperty() As Boolean Without the Instance flag, the property has to be public: Public ReadOnly Property SomeProperty() As Boolean Neither of these two are static. Cheers, Rob. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |