473,396 Members | 2,016 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,396 software developers and data experts.

? Runtime Discovery of Property Name using Reflection..

Simple question I hope.
class A
{
void SomePropertyName
{
set
{
string NameOfThisProperty = ??? // what code here to
get "SomePropertyName" at runtime?
}
}
}

Sep 28 '07 #1
2 1584
Hi bigtexan,

A base method is:

Type classAtype = typeof(A);
System.Reflection.PropertyInfo[] properties = classAtype.GetProperties();
properties[...].Name

Regards, Alex
[TechBlog] http://devkids.blogspot.com
class A
{
void SomePropertyName
{
set
{
string NameOfThisProperty = ??? // what code here to
get "SomePropertyName" at runtime?
}
}
}

Sep 29 '07 #2
Thanks.... I found it.

System.Reflection.MethodInfo.GetCurrentMethod().Na me.Substring(4)

This gets the name of the current property/method etc... durring
runtime. So when the runtime pointer is in the set property
SomePropertyName .. it returns "set_SomePropertyName" .. just trim off
the first 4 chars and your golden.

Gratis.
Sep 29 '07 #3

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

Similar topics

6
by: jason | last post by:
hello everyone, is there any way in C# to perform dynamic property discovery? i know such a thing was possible in C++ template code, but it was kind of an ugly mess. i'm just curious if there is...
4
by: Bill Borg | last post by:
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
3
by: Sampson | last post by:
I have a question about enumeration and how to populate them during runtime. I am using vb.net but will happily take any advice in c# as well. Here is an example to help illustrate what I am...
3
by: VJ | last post by:
I can't find my posting that had replies to events at runtime.. hence I am posting as new. I did earlier read all your replies. Thanks for the information. I still have not tried them. My...
3
by: cOdEmOnKeY | last post by:
I have created a component that I add to the component tray at Design time. I need to know how to access a property on this component at Runtime. From what I understand I should use Reflection to...
7
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
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...
8
by: julia_beresford | last post by:
Hi I need to create the following class at runtime: public class MyCollection : CollectionBase { public void Add(MyItem item) { List.Add(item); }
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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,...
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,...

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.