W
Walter L. Williams
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
[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