472,783 Members | 1,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Get name of current property by reflection


I wonder how to get the name of the currently executing property by using
reflection in .Net 2.0

If I use System.Reflection.MethodInfo.GetCurrentMethod().Na me from within a
property I get something like "set_MyProperty" instead of "MyProperty". Is
there a way to get the current property name without the "set_" or "get_"


May 29 '06 #1
1 7973
Hello Guido,

Welcome to the MSDN newsgroup.

As for the "System.Reflection.MethodInfo.GetCurrentMethod ()" method, it
always returns the methodinfo of the current executing function on the
stack. However, an executing function is not necessarily a property,
therefore the "System.Reflection.MethodInfo.GetCurrentMethod ()" method is
not suitable for getting property information. Also, in .net framework , a
property is actually represented by two raw accessor methods (get_PROPNAME
and set_PROPNAME), and in some languages such as C++, properties are even
directly defined by two functions. e.g.


public: __property System::Int32 get_CodePage()
public: __property void set_CodePage(System::Int32 value)

That's why the "System.Reflection.MethodInfo.GetCurrentMethod ()" method can
only return the get/set accessor function name rather than the property

Generally, we're recommended to use the "GetProperties" or "FindMembers"
method of the "Type" class to query property info from a certain class.

#Type.FindMembers Method

Hope this helps.


Steven Cheng
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.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no

May 30 '06 #2

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

Similar topics

by: Rakesh | last post by:
Hi, I am able to obtain a MenuItem object's Name property @ design-time, but am not able to get the same @ run- time...why? And since MenuItem doesn't inherit from Control class, it's not...
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. How can one get the name of the current project and the current class? This is the situation. Suppose there is a project called "P1".
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
by: clr | last post by:
I like to stamp trace logs with the name of the executing Class and Method. I can get the Class Name using GetType.Name and I can get a list of every Method in the class using...
by: Alexander Walker | last post by:
Hello I would like to write a method that allows me to pass a reference to an instance of a class, the name of a property of that class and a value to set that property to, the method would then...
by: news.microsoft.com | last post by:
How do I get the class name for a current instance. For example, if I want to know the Class Name for the current form, how do I get this programatically. Thanks
by: bigtexan | last post by:
Simple question I hope. class A { void SomePropertyName { set { string NameOfThisProperty = ??? // what code here to
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
by: =?Utf-8?B?VmljdG9y?= | last post by:
Is it a way to discover, at the run time, the name of a property of an object? In other words is it possible to create a method GetPropertyName, that takes a property of an object and returns the...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.