By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

Reflection Question

P: n/a
2131 Public Property ContactId() As SqlInt32

2132 Get

2133 Return MyBase.SqlInt32Property("ContactId")

2134 End Get

2135 Set(ByVal Value As SqlInt32)

2136 MyBase.SqlInt32Property("ContactId") = Value

2137 End Set

2138 End Property

I have a short property shown above. My app is going to have maybe properties with various names, but they will all follow a common pattern: The string refrenced in the Get and Let routine SHOULD ALWAYS equal the property name.

A slightly better way of ensuring that the string is not mispelled, it to define a module level string constant, and to reference it in the GET and LET routines. However, it would be nice if the Constant were local to both the GET and the LET routines, not the whole module. Not to mention, there is always a chance of a cut and paste error where one is changed and the other is not, leading to an error.

--------------------------------------------------------------------------------
Private Const m_ContactId As String = "ContactId"

2131 Public Property ContactId() As SqlInt32
2132 Get

2133 Return MyBase.SqlInt32Property(ContactId)

2134 End Get

2135 Set(ByVal Value As SqlInt32)

2136 MyBase.SqlInt32Property(ContactId ) = Value

2137 End Set

2138 End Property
--------------------------------------------------------------------------------

Perhaps, what I am looking for is to, if it is possible with Reflection, to dynamically determine the name of the Property sub of the current context and pass that string.

Private Const m_ContactId As String = "ContactId"

2131 Public Property ContactId() As SqlInt32
2132 Get

2133 Return MyBase.SqlInt32Property(Reflection.GetCurrentPrope rtyName())

2134 End Get

2135 Set(ByVal Value As SqlInt32)

2136 MyBase.SqlInt32Property(Reflection.GetCurrentPrope rtyName()) = Value

2137 End Set

2138 End Property
That way, if we cut and paste the property code, we do not have to worry about updating the code to change the Property name in two places, and to make sure the spelling of the string passed exactly matches the name of the property in which it is enclosed.
Is something like this possible? I imagine it looks a bit unusual.

Feb 9 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sorry, not maybe properties, many properties.

"Chad" <ch**************@unisys.com> wrote in message news:ds**********@trsvr.tr.unisys.com...
2131 Public Property ContactId() As SqlInt32

2132 Get

2133 Return MyBase.SqlInt32Property("ContactId")

2134 End Get

2135 Set(ByVal Value As SqlInt32)

2136 MyBase.SqlInt32Property("ContactId") = Value

2137 End Set

2138 End Property
I have a short property shown above. My app is going to have maybe properties with various names, but they will all follow a common pattern: The string refrenced in the Get and Let routine SHOULD ALWAYS equal the property name.

A slightly better way of ensuring that the string is not mispelled, it to define a module level string constant, and to reference it in the GET and LET routines. However, it would be nice if the Constant were local to both the GET and the LET routines, not the whole module. Not to mention, there is always a chance of a cut and paste error where one is changed and the other is not, leading to an error.

------------------------------------------------------------------------------
Private Const m_ContactId As String = "ContactId"

2131 Public Property ContactId() As SqlInt32
2132 Get

2133 Return MyBase.SqlInt32Property(ContactId)

2134 End Get

2135 Set(ByVal Value As SqlInt32)

2136 MyBase.SqlInt32Property(ContactId ) = Value

2137 End Set

2138 End Property

------------------------------------------------------------------------------

Perhaps, what I am looking for is to, if it is possible with Reflection, to dynamically determine the name of the Property sub of the current context and pass that string.

Private Const m_ContactId As String = "ContactId"

2131 Public Property ContactId() As SqlInt32
2132 Get

2133 Return MyBase.SqlInt32Property(Reflection.GetCurrentPrope rtyName())

2134 End Get

2135 Set(ByVal Value As SqlInt32)

2136 MyBase.SqlInt32Property(Reflection.GetCurrentPrope rtyName()) = Value

2137 End Set

2138 End Property
That way, if we cut and paste the property code, we do not have to worry about updating the code to change the Property name in two places, and to make sure the spelling of the string passed exactly matches the name of the property in which it is enclosed.
Is something like this possible? I imagine it looks a bit unusual.

Feb 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.