473,396 Members | 1,853 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.

Retrieving attribute information from field

I have defined my own IntegerRangeAttribute which is used like so:

[IntegerRange(DefaultValue = 2000, MinimumValue = 0, MaximumValue =
1000000)]
private Int32 iNumBurnInIterations = 2000;

At another point I want to get at that information, ie:

public Int32 GetNumPreIterations ()
{
IntegerRangeAttribute range =
GetIntegerRange(this.iNumBurnInIterations);

/* Do something here */

return (this.iNumBurnInIterations);
}

private IntegerRangeAttribute GetIntegerRange (object o)
{
MemberInfo[] ami = this.GetType().GetMembers(BindingFlags.Instance |
BindingFlags.NonPublic);
foreach (MemberInfo mi in ami)
{
if (mi.Name == o.ToString())
return ((IntegerRangeAttribute)
System.Attribute.GetCustomAttribute(mi, typeof(IntegerRangeAttribute)));
}

return (null);
}
Now the problem is, o.ToString() calls the Int32.ToString(), and the name
won't match up. I don't know of a good way to get that string
programmatically.

Is there a way to get that variable name? Is there a better way to retrieve
the attribute?
================================================== ==
Walter Williams
Software Engineer
Sawtooth Software, Inc.
http://www.sawtoothsoftware.com
----------------------------------------------------
"Do, or do not. There is no try."

Nov 22 '05 #1
1 1370
>Is there a way to get that variable name?

Not from the int value, no. You have to use the variable name as a
string, "iNumBurnInIterations".

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2

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

Similar topics

2
by: marcelf3 | last post by:
I´ve got a sql table which has 3 fields. Their relation to each other is like this example. | CARS | YEAR | PRICE | ford 2000 ford 2001 ford ...
6
by: anon | last post by:
Post Forwarding question...... For this control below, <asp:Button runat="server" PostTargetUrl="page2.aspx" /> The Attribute: PostTargetUrl="page2.aspx" Is this PostTargetUrl Attribute...
1
by: Walter L. Williams | last post by:
I have defined my own IntegerRangeAttribute which is used like so: private Int32 iNumBurnInIterations = 2000; At another point I want to get at that information, ie: public Int32...
8
by: CJM | last post by:
I'm trying to retrieve the users email address via ADSI in ASP. So far, I have the following code: Set oUser = GetObject("WinNT://domain/" & Request.Form("UID") & ",user") Response.Write...
3
by: Frankie | last post by:
Hi, I am working on a form in which in a certain field a number of an employee can be entered. After entering this number I would like to show in the same form (real time) the name etc. of this...
0
by: Kurt Ng | last post by:
Hi, y'all. I am working on retrieving file version info on a third party dll. I have used the FileVersionInfo class to retrieve all of the standard version information already such as...
11
by: Nemisis | last post by:
Hi everyone, sorry if this post gets really long, i just wanna make sure i fully explain what i am trying to do. I am new to OOP and .net 2.0, so if this is obvious, i am sorry. I have wrote a...
2
by: 4Ankit | last post by:
hello all, i am having some difficulty retrieving information from my form. I want to add content in my table but the content i want to add to the table is what the user inputs in my form. ...
6
by: MLM450 | last post by:
Is it possible to retrieve an item's "sizeconst" value dynamically? I have the following member defined in a class: private char units; I want the code that values the units member to know...
1
by: gunjangogia | last post by:
Hi everyone, Could someone please help me out. I am having problems retrieving information from a table where 2 attributes are foreign keys of the SAME attribute in another table.... The tables...
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.