473,387 Members | 1,534 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,387 software developers and data experts.

Property name

Hi,

class Resource // This class is autogenerated by Visual Studio.
{
internal static string M001
{
get{ return ResourceManager.GetString("M001"); }
}
}
public Main()
{
/*
Logging a message from resources.
If I hover the mouse over M001 in Visual Studio, the tooltip says
"Looks up a localized message similar to MESSAGE TEXT COMES HERE".
*/
LogMessage( Resource.M001 );
}

public LogMessage( ?SomeType? param )
{
/******
I don't want to get "param" as a string here. Instead, I want to
get the name of the property passed as a parameter to this method. Something
like:
******/

Console.Write( param.(MethodInfo or whatever).Name ); // Prints
"M001".
}
In other words, I want to:

- Pass a property (Resource.M001) to a method directly, as a C# identifier,
as this provides compiler type checking and context help.
- In the called method, I want to get the passed property's name ("M001"),
as this name contains encoded additional information about the string the
property retrieves from resources.

I wonder if the above is possible in C# 2.0.

Thanks

Feb 8 '07 #1
4 1710
On Feb 7, 5:45 pm, <muri...@nospam.nospamwrote:
Hi,

class Resource // This class is autogenerated by Visual Studio.
{
internal static string M001
{
get{ return ResourceManager.GetString("M001"); }
}

}

public Main()
{
/*
Logging a message from resources.
If I hover the mouse over M001 in Visual Studio, the tooltip says
"Looks up a localized message similar to MESSAGE TEXT COMES HERE".
*/
LogMessage( Resource.M001 );

}

public LogMessage( ?SomeType? param )
{
/******
I don't want to get "param" as a string here. Instead, I want to
get the name of the property passed as a parameter to this method. Something
like:
******/

Console.Write( param.(MethodInfo or whatever).Name ); // Prints
"M001".

}

In other words, I want to:

- Pass a property (Resource.M001) to a method directly, as a C# identifier,
as this provides compiler type checking and context help.
- In the called method, I want to get the passed property's name ("M001"),
as this name contains encoded additional information about the string the
property retrieves from resources.

I wonder if the above is possible in C# 2.0.
Nope. Sorry.

Passing Resource.M001 to a method results in a pass-by-value,
something being pushed on the stack. Once your method starts running,
there is no longer any record of where that value came from. (Apart
from doing some horrible, painful, stack walking and decompiling
stuff.)

Even if you were to pass it as "ref" (which you can't do with
properties anyway), you still couldn't figure out (easily) from which
type the value (to which you now have a reference) came, and which
property within that type was used to give you the value.

So... sorry. No dice.

Feb 8 '07 #2
Hi,

I'm with Mark here if our understanding of your question is right. Please
feel free to let us know if you think we may have misunderstood your
question.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 12 '07 #3
Sorry about the name, I meant Bruce here.

Feb 12 '07 #4
Thanks Bruce and Walter. Bruce's answer ("not possible") is what I expected
to get anyway. I wanted to avoid hard-coding M001 etc. prefixes into
resource text, but that's what I ended up with.


"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
On Feb 7, 5:45 pm, <muri...@nospam.nospamwrote:
>Hi,

class Resource // This class is autogenerated by Visual Studio.
{
internal static string M001
{
get{ return ResourceManager.GetString("M001"); }
}

}

public Main()
{
/*
Logging a message from resources.
If I hover the mouse over M001 in Visual Studio, the tooltip
says
"Looks up a localized message similar to MESSAGE TEXT COMES HERE".
*/
LogMessage( Resource.M001 );

}

public LogMessage( ?SomeType? param )
{
/******
I don't want to get "param" as a string here. Instead, I want to
get the name of the property passed as a parameter to this method.
Something
like:
******/

Console.Write( param.(MethodInfo or whatever).Name ); // Prints
"M001".

}

In other words, I want to:

- Pass a property (Resource.M001) to a method directly, as a C#
identifier,
as this provides compiler type checking and context help.
- In the called method, I want to get the passed property's name
("M001"),
as this name contains encoded additional information about the string the
property retrieves from resources.

I wonder if the above is possible in C# 2.0.

Nope. Sorry.

Passing Resource.M001 to a method results in a pass-by-value,
something being pushed on the stack. Once your method starts running,
there is no longer any record of where that value came from. (Apart
from doing some horrible, painful, stack walking and decompiling
stuff.)

Even if you were to pass it as "ref" (which you can't do with
properties anyway), you still couldn't figure out (easily) from which
type the value (to which you now have a reference) came, and which
property within that type was used to give you the value.

So... sorry. No dice.

Feb 12 '07 #5

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

Similar topics

11
by: Laszlo Zsolt Nagy | last post by:
My problem is about properties and the virtuality of the methods. I would like to create a property whose get and set methods are virtual. I had the same problems in Delphi before and the solution...
4
by: Jimbo | last post by:
I am sort of new to C#. Currently have a private property called "_name" in a class. I have written a public getter and setter routine for it called "Name". Currently, the getter for the...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
0
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties...
1
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties...
5
by: ronlahav | last post by:
Dear all i Wonder how can i edit a node property (in C# not by hand :) ) i have the follwing XMl file (hibernate.cfg.xml) <?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration ...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
3
by: Peter Gast | last post by:
Hi, I need as a parameter for a control the names of my properties as a string. How can I get the name of the property as a string during runtime Example: Private _MyVar As Double Public...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.