473,626 Members | 3,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to retrieve the variable name of a property ?

I have started looking at the nhibernate framework, but do not really
like the string based API which makes it impossible to use automatic
refactoring of a property name without the risk of getting problems
where the property has been refered to as a string...

Therefore I am wondering if it would be even theoretically possible to
improve such a framework with stronger typing, to avoid the usage of
strings.

For example, consider this code example from the NHibernate framework:
IList cats = sess.CreateCrit eria(typeof(Cat )).AddOrder(
Order.Asc("Name ") ).List();

Here is what I wish could be done instead:
IList cats = sess.CreateCrit eria(typeof(Cat )).AddOrder(
Order.Asc(Cat.N ame) ).List();

Obviously the above kind of syntax would not even compile unless there
would be a static "Name" property in the Cat class, but perhaps
something like this might be possible:
Cat aCat = new Cat();
IList cats = sess.CreateCrit eria(typeof(Cat )).AddOrder(
Order.Asc(aCat. Name) ).List();
But the question is whether it would be at all possible to implement
the "Order.Asc" method
so that its formal parameter could be used to retrieve the string
"Name" from the actual parameter in the invocation ?

/ Tomas

Aug 7 '06 #1
1 1644
Hello Tomas,

unfortunately you cannot have such a construct as the language
interpretes the <instance>.<pro pertyas the reference to the property
value not the actual property. So, you cannot retrieve the name of the
property that was passed to the method as there is no such information.

It is a Good Thing that there is such a gap as you cannot create
"property-specific" methods that will introduce complexity and bugs of
cource.

Regards,
Tasos
to************* @bloglines.com wrote:
I have started looking at the nhibernate framework, but do not really
like the string based API which makes it impossible to use automatic
refactoring of a property name without the risk of getting problems
where the property has been refered to as a string...

Therefore I am wondering if it would be even theoretically possible to
improve such a framework with stronger typing, to avoid the usage of
strings.

For example, consider this code example from the NHibernate framework:
IList cats = sess.CreateCrit eria(typeof(Cat )).AddOrder(
Order.Asc("Name ") ).List();

Here is what I wish could be done instead:
IList cats = sess.CreateCrit eria(typeof(Cat )).AddOrder(
Order.Asc(Cat.N ame) ).List();

Obviously the above kind of syntax would not even compile unless there
would be a static "Name" property in the Cat class, but perhaps
something like this might be possible:
Cat aCat = new Cat();
IList cats = sess.CreateCrit eria(typeof(Cat )).AddOrder(
Order.Asc(aCat. Name) ).List();
But the question is whether it would be at all possible to implement
the "Order.Asc" method
so that its formal parameter could be used to retrieve the string
"Name" from the actual parameter in the invocation ?

/ Tomas
Aug 7 '06 #2

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

Similar topics

6
4420
by: Miguel Orrego | last post by:
Hi, I have found some code that authenticates users agains a domain using ADSI. I then redirect to another page and pass the username they have entered as a string. However, it would be nice to also get their full name from Active Directory once authenticated. Can anyone suggest how I may modify this code to achieve this? I would also like to pass their full name to the next page as a string. The code I found: <%
7
1978
by: Klaus Johannes Rusch | last post by:
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename(); somename.show() Note that the class name "somename" is reused for the variable name.
1
2072
by: Epson Barnett | last post by:
Hi, I'm new to C# and I'd like to be able to reference a field of an object using a variable instead of literal text. In the PHP scripting language, you can create a variable: $var = "name"; and another variable: $name = "Epson"; Then you can refer to $name, or $$var. They will equal the same thing.
20
6956
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
9
6817
by: Don | last post by:
Say I have a class like so: Public Class MyClass Public Prop1 as Integer Public Prop2 As Integer Public Prop3 As Integer End Class Is it possible to retrieve a list of the variables or objects declared within an instance of that class if they are declared with Public (or
6
1416
by: PJ6 | last post by:
I would like to refer to properties in code without having to resort to using a string for the name. AddessOf gives me this ability for methods, but I can't find a single way to point that at the Get or Set methods of properties directly. Why don't I want to use a string? Well, I want to know at design time that my property references aren't broken, much the same way I can have this when using regular delegates. Is this possible?
4
3489
by: Fred Lazy | last post by:
Is is possible to retrieve the name of an .js file from within the .js file itself: For example, if the file is named "bla.js" and it is imported into an html document: <script type="text/javascript" src="bla.js"></script> Is it then possible from within "bla.js" get the name of the .js file similarly to the window.location property, but for the .js file itself and not the window the .js file is contained in. In other words, does the
1
1880
by: Gene | last post by:
I would like to know if the following is even possible with the visual studio.net Setup and Deployment project. 1. During the deployment after creation of application directory the setup needs to prompt user to select another location to send a data file elsewhere on target machine (with ability to create this directory). 2. After that this secondary location selected/created by the user,
12
77981
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table emp_mstr is as follows :- CREATE TABLE EMP_MSTR( EMP_NO VARCHAR(10) PRIMARY KEY, PASSWORD...
0
8272
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8205
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
8644
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
6126
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
5579
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
4094
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
2632
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
1
1817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1516
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.