VB2008: Getting the System.Reflection.PropertyInfo from within a class property 
Author Message
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property

I am working on an error handler class. Within a property set method of a
given class property I'd like to pass the PropertyInfo to a function.
Imagine something like:

Public Class MyClass
    ....
    Public Property MyProperty() as String
        Get
            Return _myProperty
        End Get
        Set (ByVal pMyProperty as String)
            ' Validate property. If there's an error, add an item to the
error handler
            MyErrorHandler.AddError([MyProperty], errorCode) ' <--- How to
get the reference to 'MyProperty'?
        End Set
    End Property
    ....
End Class

Public Class MyErrorHandler
    ....
    Public Sub AddError(ByVal pProperty As System.Reflection.PropertyInfo,
pErrorCode As Integer)
        ....
    End Sub
    ....
End Class

Many thanks for any suggestions,
Etienne



Sun, 12 Dec 2010 16:47:42 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property

Quote:

> I am working on an error handler class. Within a property set
> method of a given class property I'd like to pass the PropertyInfo
> to a function. Imagine something like:

You'll have better luck posting in a group with "dotnet" in its name.
The .vb. groups are for VB6 and earlier.

--
        Jim



Sun, 12 Dec 2010 17:17:15 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property
Hi Etienne,

Best to ask dotnet questions for vb in the:
 microsoft.public.dotnet.languages.vb
group.

As to your question, I think you'll need to do something like:

 MyErrorHandler.AddError(GetType(TheClass)GetProperty("MyProperty"),
errorCode)


Quote:
>I am working on an error handler class. Within a property set method of a
>given class property I'd like to pass the PropertyInfo to a function.
>Imagine something like:

> Public Class MyClass
>    ....
>    Public Property MyProperty() as String
>        Get
>            Return _myProperty
>        End Get
>        Set (ByVal pMyProperty as String)
>            ' Validate property. If there's an error, add an item to the
> error handler
>            MyErrorHandler.AddError([MyProperty], errorCode) ' <--- How to
> get the reference to 'MyProperty'?
>        End Set
>    End Property
>    ....
> End Class

> Public Class MyErrorHandler
>    ....
>    Public Sub AddError(ByVal pProperty As System.Reflection.PropertyInfo,
> pErrorCode As Integer)
>        ....
>    End Sub
>    ....
> End Class

> Many thanks for any suggestions,
> Etienne



Sun, 12 Dec 2010 17:30:17 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property
Hi Bill,

Thanks for your quick reply. Sorry for having addressed the wrong group,
I'll put my question there. As to my question, the idea was to have a syntax
that does not hard-code the property name like ...GetProperty("MyProperty"),
but rather uses Intellisense. We'll see what ideas I'll get on the
appropriate discussion group.

Kind regards,
Etienne


Quote:
> Hi Etienne,

> Best to ask dotnet questions for vb in the:
> microsoft.public.dotnet.languages.vb
> group.

> As to your question, I think you'll need to do something like:

> MyErrorHandler.AddError(GetType(TheClass)GetProperty("MyProperty"),
> errorCode)



>>I am working on an error handler class. Within a property set method of a
>>given class property I'd like to pass the PropertyInfo to a function.
>>Imagine something like:

>> Public Class MyClass
>>    ....
>>    Public Property MyProperty() as String
>>        Get
>>            Return _myProperty
>>        End Get
>>        Set (ByVal pMyProperty as String)
>>            ' Validate property. If there's an error, add an item to the
>> error handler
>>            MyErrorHandler.AddError([MyProperty], errorCode) ' <--- How to
>> get the reference to 'MyProperty'?
>>        End Set
>>    End Property
>>    ....
>> End Class

>> Public Class MyErrorHandler
>>    ....
>>    Public Sub AddError(ByVal pProperty As System.Reflection.PropertyInfo,
>> pErrorCode As Integer)
>>        ....
>>    End Sub
>>    ....
>> End Class

>> Many thanks for any suggestions,
>> Etienne



Sun, 12 Dec 2010 18:44:37 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property
Hi Etienne,


Quote:
> Hi Bill,

> Thanks for your quick reply. Sorry for having addressed the wrong group,
> I'll put my question there. As to my question, the idea was to have a
> syntax that does not hard-code the property name like
> ...GetProperty("MyProperty"), but rather uses Intellisense. We'll see what
> ideas I'll get on the appropriate discussion group.

Unfortunately you'll find the answer is there is no way.  It is one of the
things I have asked the Vb team to include in the language syntax.

A slightly different approach you can try is the use of a dependcy property
kind of model. I think Rocky Lkhota switched his object model over to that
in CSLA.



Sun, 12 Dec 2010 18:54:55 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property



Quote:

>Unfortunately you'll find the answer is there is no way.  It is one of the
>things I have asked the Vb team to include in the language syntax.

I'll bet they'll get right on that McBarfy, won't they?  Yeah right.
You'd have us believe that you're more important than the entire VB6
community.  Sure pal.  Whatever you say must be gospel.

Frank



Mon, 13 Dec 2010 01:24:26 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property

Quote:
>>Unfortunately you'll find the answer is there is no way.  It is one of the
>>things I have asked the Vb team to include in the language syntax.

> I'll bet they'll get right on that McBarfy, won't they?  Yeah right.
> You'd have us believe that you're more important than the entire VB6
> community.  Sure pal.  Whatever you say must be gospel.

No, you unbelievably narrow-minded twit who has nothing better to do than
complain, he'd have you believe that he has a close relationship with the VB
team at Microsoft, because HE DOES.


Mon, 13 Dec 2010 04:15:13 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property


Quote:

>  Whatever you say must be gospel.

Thanks Mr "dot nyet".  So nice to see you are still my #1 fan :)


Mon, 13 Dec 2010 04:42:00 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property



Quote:


>>>Unfortunately you'll find the answer is there is no way.  It is one of the
>>>things I have asked the Vb team to include in the language syntax.

>> I'll bet they'll get right on that McBarfy, won't they?  Yeah right.
>> You'd have us believe that you're more important than the entire VB6
>> community.  Sure pal.  Whatever you say must be gospel.

>No, you unbelievably narrow-minded twit who has nothing better to do than
>complain, he'd have you believe that he has a close relationship with the VB
>team at Microsoft, because HE DOES.

Well, thank you for your words of infinite wisdom Mr. Johnson.  But the
fact that the racist .NET bigot McBarfy could represent the VB community
just goes to prove that Microsoft has completely lost their marbles.
Good luck with that and good luck with your career.  I'll pass, thank
you very much.

Frank



Mon, 13 Dec 2010 05:37:56 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property

Quote:
> Well, thank you for your words of infinite wisdom Mr. Johnson.
> But the fact that the racist .NET bigot McBarfy could represent
> the VB community just goes to prove that Microsoft has completely
> lost their marbles.

Agreed. Micro$oft have lost mtheir marbles. But I don't think they have lost
them completely. I believe they will very soon sack him and remove his MVP
status. Time will tell.

Mike



Mon, 13 Dec 2010 05:59:09 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property


Quote:

> Agreed. Micro$oft have lost mtheir marbles. But I don't think they have
> lost them completely. I believe they will very soon sack him and remove
> his MVP status. Time will tell.

Oh, poor old Mikey, still haven't got over the fact they realized the
mistake they made with you and kicked you out hey ?

BTW: looks like you're having "issues" with a lot of folks around here
lately Mieky ?  Something wrong at home ?



Mon, 13 Dec 2010 06:22:53 GMT  
 VB2008: Getting the System.Reflection.PropertyInfo from within a class property

Quote:



>> ... just goes to prove that Microsoft has completely
>> lost their marbles.
> Agreed. Micro$oft have lost their marbles.  

They haven't "lost" their marbles at all.

The current location of Microsoft's Marbles(TM) has been virtualised to
an alternative, physical location not known to (or needing to be known
by) anyone outside the Redmond Reality Distortion Zone.

As expected, a copy of this location is stored in the Windows Registry,
access to which is /also/ virtualised and, because of this, Legacy
applications may not necessarily be able to read this location in order
to ascertain the Marbles' current location.

Both locations (file system and Registry) are liable to change so an API
method will be provided in order to retrieve them.  This method will
take arguments of the enumerated types DayOfTheWeek,
DirectionTheWindIsBlowing and the result of the function
IsThereAnRInTheMonth().

;-)

Regards,
    Phill  W.



Mon, 13 Dec 2010 20:26:27 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Not getting Events from classes within classes.

2. dotnet indexed property access via propertyinfo getvalues

3. Retrieve name of Function, Sub, Class, Property etc from within that item during runtime

4. Problem getting Application class properties

5. Getting the properties of VB class at runtime

6. Possible to use Reflection on Registry Class?

7. Using reflection to create class instance

8. Sub Class Reflection

9. Getting the object name via reflection

10. Release a reference from System.Reflection

11. How far can System.Reflection take you?

12. Reflection: Getting fields in structure

 

 
Powered by phpBB® Forum Software