I want to get a property's name from the property.
e.g. not this....
this.txtField.DataBindings.Add("Text", myObject,"MyFieldOrProperty");
but this....
this.txtEmail.DataBindings.Add("Text", myObject,<someway of getting name of
MyObject.MyFieldOrProperty without using literal>);
TIA
Sam Martin 4 1138
Sam,
You need some sort of reference to the property that you want to use.
Basically, you would have to use reflection to find the property that you
want to use, and then pass the Name property of the associated PropertyInfo
instance.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... I want to get a property's name from the property.
e.g. not this.... this.txtField.DataBindings.Add("Text", myObject,"MyFieldOrProperty");
but this.... this.txtEmail.DataBindings.Add("Text", myObject,<someway of getting name of MyObject.MyFieldOrProperty without using literal>);
TIA
Sam Martin
yeah, kind of
I know I'll need to use reflection to get to it, but i need to be able to
get almost like a reference to a Property from a property.
It is possible to get from a MyClass.Property to a PropertyInfo for the
property. Without having to loop through the properties for a type and
checking the PI.Name against a literal. I don't mind doing the loop, but I
don't want to use a literal.
Any ideas Nick?
Sam
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eF**************@TK2MSFTNGP10.phx.gbl... Sam,
You need some sort of reference to the property that you want to use. Basically, you would have to use reflection to find the property that you want to use, and then pass the Name property of the associated PropertyInfo instance.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message news:%2****************@tk2msftngp13.phx.gbl...I want to get a property's name from the property.
e.g. not this.... this.txtField.DataBindings.Add("Text", myObject,"MyFieldOrProperty");
but this.... this.txtEmail.DataBindings.Add("Text", myObject,<someway of getting name of MyObject.MyFieldOrProperty without using literal>);
TIA
Sam Martin
Sam,
The only way I can think of doing this would be to get the call stack,
and parse the name of the method in the MethodInfo instance attached to each
StackFrame. For a property, you will have to remove the get_ and set_
prefixes.
However, I can't recommend doing this, because it would be a huge
performance killer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:O1******************@TK2MSFTNGP15.phx.gbl... yeah, kind of
I know I'll need to use reflection to get to it, but i need to be able to get almost like a reference to a Property from a property. It is possible to get from a MyClass.Property to a PropertyInfo for the property. Without having to loop through the properties for a type and checking the PI.Name against a literal. I don't mind doing the loop, but I don't want to use a literal.
Any ideas Nick?
Sam
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eF**************@TK2MSFTNGP10.phx.gbl... Sam,
You need some sort of reference to the property that you want to use. Basically, you would have to use reflection to find the property that you want to use, and then pass the Name property of the associated PropertyInfo instance.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message news:%2****************@tk2msftngp13.phx.gbl...I want to get a property's name from the property.
e.g. not this.... this.txtField.DataBindings.Add("Text", myObject,"MyFieldOrProperty");
but this.... this.txtEmail.DataBindings.Add("Text", myObject,<someway of getting name of MyObject.MyFieldOrProperty without using literal>);
TIA
Sam Martin
Thanks nick,
we've opted for keeping a constant string name for each property for each
component. a bit of an overkill, but works.
cheers
sam
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl... Sam,
The only way I can think of doing this would be to get the call stack, and parse the name of the method in the MethodInfo instance attached to each StackFrame. For a property, you will have to remove the get_ and set_ prefixes.
However, I can't recommend doing this, because it would be a huge performance killer.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message news:O1******************@TK2MSFTNGP15.phx.gbl... yeah, kind of
I know I'll need to use reflection to get to it, but i need to be able to get almost like a reference to a Property from a property. It is possible to get from a MyClass.Property to a PropertyInfo for the property. Without having to loop through the properties for a type and checking the PI.Name against a literal. I don't mind doing the loop, but I don't want to use a literal.
Any ideas Nick?
Sam
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eF**************@TK2MSFTNGP10.phx.gbl... Sam,
You need some sort of reference to the property that you want to use. Basically, you would have to use reflection to find the property that you want to use, and then pass the Name property of the associated PropertyInfo instance.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message news:%2****************@tk2msftngp13.phx.gbl... I want to get a property's name from the property.
e.g. not this.... this.txtField.DataBindings.Add("Text", myObject,"MyFieldOrProperty");
but this.... this.txtEmail.DataBindings.Add("Text", myObject,<someway of getting name of MyObject.MyFieldOrProperty without using literal>);
TIA
Sam Martin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ray Tayek |
last post by:
hi, trying to convert some csv files into xsml and pulling a few hairs
out :(. using the files below. a java program will parse the csv and
take care of strange names and notes that line breaks in...
|
by: Helmut |
last post by:
I have a strange problem in my dotnet Windows service:
I have developed a service, using the core of the "windows service
sample" found all over the net. Its like:
....
############...
|
by: Vijay Kumar R Zanvar |
last post by:
Did you know that the following if statement is semantically
right, but could logically be wrong?
if ( i = 2 )
{
/* do something */
}
Tip:
|
by: Nuno Magalhaes |
last post by:
Hello,
In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest
|
by: .NET Follower |
last post by:
hi,
I had posted a query
Subj:Integrating ASP.NET Web Projects to share session variables
But it seems no one has the answer to the problem
very strange......
--
Thanks and Regards,
|
by: Sandy |
last post by:
Hello -
I have a strange file that I did not add to my app and don't know how it got
there.
It's in a folder called Login and the name of the file is "ve-AE.tmp"
It has text like:
...
|
by: Brian Hirt |
last post by:
I've having a strange issue with pg_autovacuum. I have a table with
about 4 million rows in 20,000 pages. autovacuum likes to vacuum
and/or analyze it every 45 minutes or so, but it probably...
|
by: jht5945 |
last post by:
For example I wrote a function:
function Func()
{
// do something
}
we can call it like:
var obj = new Func(); // call it as a constructor
or
var result = Func(); // call it as...
|
by: =?GB2312?B?yum09MXt?= |
last post by:
today I forgot to include some header,then I found the error message by the compiler is quite strange.
so I want to know exactly the inner details of the compiler impletation,if possible.
and I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
| | |