473,888 Members | 1,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1592
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******@discu ssions.microsof t.com> wrote in message
news:CD******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:CD******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:FA******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:CD******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:FA******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:CD******** *************** ***********@mic rosoft.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
3933
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 doesn't evaluate the second argument if the first is a valid key? For now I'll code around it, but this behavior surprised me a bit...
1
5398
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 paragraphs or 2020 characters) when they click on the submit button nothing happens. When I say nothing happens I mean just that, nothing at all happens the page just sits there as if nothing at all happened. If I remove one line for the textarea,...
5
6611
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
1905
by: Duck Dodgers | last post by:
Here is my situation class base { }; class child1 { int data; }; class child2 {
2
2911
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" action="product" method="post" name="product" onSubmit="do_action_form(); return true;"> .... <script> // .. setup xmlhttp here.
7
3126
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 { ..... public object lockObject = new object(); }
3
30224
by: ElBeardo | last post by:
Hello, Im new to Python.. so this is a newbee question. Id like to put the value enterd in the entryfield in a variable. Im trying to build a calculator with python and TKinter, coding it in just python works good. But making it with TK is a bit hard. This is my unfinished code, i have tryed get() in many ways,.but I cant make it work. Im only need to get knowledge about using get() now,.. I now there is other thing undone in this...
5
18530
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 infiormation. echo php_uname(); echo php_uname(n); $hostname = gethostbyaddr($_SERVER);
7
2320
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 post method <form name="input" action="index2.htm" method="get"> Name: <input type="text" name="user" /> <br /> <input type="radio" name="sex" value="male" /> Male<br /> <input type="radio" name="sex" value="female" /> Female <br /> <input...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10882
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10438
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7990
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5817
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4243
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.