473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Need "get" accessor to return property name

Hello,
I've got a simple shared property, e.g.

Public Class dbObject
Private Const m_ID As String = "ID"
Public Shared ReadOnly Property ID() As String
Get
Return m_ID
End Get
End Property
End Class

Rather than use the private variable m_ID, I'd rather just return the name
of the property as a string, e.g. return me.PropertyName, to save on code and
typos. But, "me" is not valid since this is not an instance (it's shared),
and I can't figure out the syntax to do what I know is possible via
reflection. Any thoughts on how to get a string for the name of a shared
property within the get accessor?

Thanks,
Bill

Nov 18 '05 #1
4 1572
Hi Bill,

Watch out for that word "Simple!" What you have is not simple; in fact, it
shouldn't even compile. You can't reference an instance member from a static
(shared) member.

But you don't want to do that. Just keep that in mind for future reference.

Now, I may be missing something, but how about:

Public Shared ReadOnly Property ID() As String
Get
Return "ID"
End Get
End Property

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Hello,
I've got a simple shared property, e.g.

Public Class dbObject
Private Const m_ID As String = "ID"
Public Shared ReadOnly Property ID() As String
Get
Return m_ID
End Get
End Property
End Class

Rather than use the private variable m_ID, I'd rather just return the name
of the property as a string, e.g. return me.PropertyName, to save on code and typos. But, "me" is not valid since this is not an instance (it's shared),
and I can't figure out the syntax to do what I know is possible via
reflection. Any thoughts on how to get a string for the name of a shared
property within the get accessor?

Thanks,
Bill

Nov 18 '05 #2
That works, it's just that I need to type the property name and the string
the same for the several hundred of these that I'll do, and thought I could
eliminate some code and reduce errors by making them the same "by
definition". I'm going to keep poking around at it, because I know the system
knows which get accessor I'm in, and therefore must know the name of the
property (seems even easier if it's static). Anyway, not my biggest problem
at the moment; all I'm trying to do is create a shared class that has my db
column names, to give me some intellisense in my loosely-typed system. Thanks
for the help.

"Kevin Spencer" wrote:
Hi Bill,

Watch out for that word "Simple!" What you have is not simple; in fact, it
shouldn't even compile. You can't reference an instance member from a static
(shared) member.

But you don't want to do that. Just keep that in mind for future reference.

Now, I may be missing something, but how about:

Public Shared ReadOnly Property ID() As String
Get
Return "ID"
End Get
End Property

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Hello,
I've got a simple shared property, e.g.

Public Class dbObject
Private Const m_ID As String = "ID"
Public Shared ReadOnly Property ID() As String
Get
Return m_ID
End Get
End Property
End Class

Rather than use the private variable m_ID, I'd rather just return the name
of the property as a string, e.g. return me.PropertyName, to save on code

and
typos. But, "me" is not valid since this is not an instance (it's shared),
and I can't figure out the syntax to do what I know is possible via
reflection. Any thoughts on how to get a string for the name of a shared
property within the get accessor?

Thanks,
Bill


Nov 18 '05 #3
Hi Bill,

The problem with using Reflection to do this is using Reflection to do this.
;-)

Reflection can be pretty darned expensive.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
That works, it's just that I need to type the property name and the string
the same for the several hundred of these that I'll do, and thought I could eliminate some code and reduce errors by making them the same "by
definition". I'm going to keep poking around at it, because I know the system knows which get accessor I'm in, and therefore must know the name of the
property (seems even easier if it's static). Anyway, not my biggest problem at the moment; all I'm trying to do is create a shared class that has my db column names, to give me some intellisense in my loosely-typed system. Thanks for the help.

"Kevin Spencer" wrote:
Hi Bill,

Watch out for that word "Simple!" What you have is not simple; in fact, it shouldn't even compile. You can't reference an instance member from a static (shared) member.

But you don't want to do that. Just keep that in mind for future reference.
Now, I may be missing something, but how about:

Public Shared ReadOnly Property ID() As String
Get
Return "ID"
End Get
End Property

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Hello,
I've got a simple shared property, e.g.

Public Class dbObject
Private Const m_ID As String = "ID"
Public Shared ReadOnly Property ID() As String
Get
Return m_ID
End Get
End Property
End Class

Rather than use the private variable m_ID, I'd rather just return the name of the property as a string, e.g. return me.PropertyName, to save on code
and
typos. But, "me" is not valid since this is not an instance (it's

shared), and I can't figure out the syntax to do what I know is possible via
reflection. Any thoughts on how to get a string for the name of a shared property within the get accessor?

Thanks,
Bill


Nov 18 '05 #4
Agreed that it's not worth it in this case. I guess I'll just have to
proofread better and test for a change. Thanks.

"Kevin Spencer" wrote:
Hi Bill,

The problem with using Reflection to do this is using Reflection to do this.
;-)

Reflection can be pretty darned expensive.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
That works, it's just that I need to type the property name and the string
the same for the several hundred of these that I'll do, and thought I

could
eliminate some code and reduce errors by making them the same "by
definition". I'm going to keep poking around at it, because I know the

system
knows which get accessor I'm in, and therefore must know the name of the
property (seems even easier if it's static). Anyway, not my biggest

problem
at the moment; all I'm trying to do is create a shared class that has my

db
column names, to give me some intellisense in my loosely-typed system.

Thanks
for the help.

"Kevin Spencer" wrote:
Hi Bill,

Watch out for that word "Simple!" What you have is not simple; in fact, it shouldn't even compile. You can't reference an instance member from a static (shared) member.

But you don't want to do that. Just keep that in mind for future reference.
Now, I may be missing something, but how about:

Public Shared ReadOnly Property ID() As String
Get
Return "ID"
End Get
End Property

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
> Hello,
> I've got a simple shared property, e.g.
>
> Public Class dbObject
> Private Const m_ID As String = "ID"
> Public Shared ReadOnly Property ID() As String
> Get
> Return m_ID
> End Get
> End Property
> End Class
>
> Rather than use the private variable m_ID, I'd rather just return the name > of the property as a string, e.g. return me.PropertyName, to save on code and
> typos. But, "me" is not valid since this is not an instance (it's shared), > and I can't figure out the syntax to do what I know is possible via
> reflection. Any thoughts on how to get a string for the name of a shared > property within the get accessor?
>
> Thanks,
> Bill
>


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Dave Opstad | last post by:
In this snippet: d = {'x': 1} value = d.get('x', bigscaryfunction()) the bigscaryfunction is always called, even though 'x' is a valid key. Is there a "short-circuit" version of get that...
1
by: Pete Mahoney | last post by:
Ok I use a textarea to store data input by the user, and then upon them clicking the submit button I store this data to a database. The problem is once the user inputs too much data (about 3...
5
by: kelvin | last post by:
How do I use get data in a url sent from aform on an other page. All i want to do is take this data and display it on the page. thanking you in anticipation
5
by: Duck Dodgers | last post by:
Here is my situation class base { }; class child1 { int data; }; class child2 {
2
by: Jason Morehouse | last post by:
Hello, Anyone know if it's possible to speak with the server via xmlhttp.open while the browser is doing a post -- file upload in this case: <form enctype="multipart/form-data"...
7
by: Javaman59 | last post by:
This is probably common knowledge to .Net gurus, but please bear with me while I share a discovery with the group... I needed to create a public lock on a class, as follows... class Locked {...
3
by: ElBeardo | last post by:
Hello, I´m new to Python.. so this is a newbee question. I´d like to put the value enterd in the entryfield in a variable. I´m trying to build a calculator with python and TKinter, coding it in...
5
by: chowdhury | last post by:
Dear Sir, i need to get the client's computer name using php. i tried some code like as below. but i get only client public ip or server information. so can anyone help me to get client's...
7
by: Spencer Killen | last post by:
Hey I have a short little poll thing and i'd like to transfer the results to another page through url like ...com/?x=12&y=55 hers what I got so far: by the way my website doesn't let me use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.