K
Kenneth Baltrinic
I have the following routine that is always throwing the error at the end.
It never returns from within the foreach loop because the if expression is
always evaluating to false apparently. This is something of a problem. The
comparison is between two objects (Handler.Data is defined as returning an
object.), but these objects are always nothing more than boxed value types
(either strings or ints or an int based enumeration). If for the sake of a
particular test where I knew all the values were ints, I recoded the
comparison to look like
if((int)Handler.Data == (int)Value)
and all worked fine. The problem is I can rely on this assumption. Any
suggestions on this issue?
protected virtual void HandleValueChange(ref object Value)
{
foreach(PSCForms.MenuHandler Handler in MenuHandlers)
if(Handler.Data == Value)
{
Handler.MenuItem.DefaultItem = true;
this.Text = Handler.MenuItem.Text.Replace("&", "");
return;
}
throw new ArgumentOutOfRangeException(
"Value", Value, "The value is not is the list of acceptable values.");
}
P.S. One more bizarre thing, if I put (Handler.Data == Value) in a watch
window and step through the routine, the window indicates that the
expression evaluates to true for the appropriate iteration, but the code
within the if block still does not run. Could this be a C# bug?
--Ken
It never returns from within the foreach loop because the if expression is
always evaluating to false apparently. This is something of a problem. The
comparison is between two objects (Handler.Data is defined as returning an
object.), but these objects are always nothing more than boxed value types
(either strings or ints or an int based enumeration). If for the sake of a
particular test where I knew all the values were ints, I recoded the
comparison to look like
if((int)Handler.Data == (int)Value)
and all worked fine. The problem is I can rely on this assumption. Any
suggestions on this issue?
protected virtual void HandleValueChange(ref object Value)
{
foreach(PSCForms.MenuHandler Handler in MenuHandlers)
if(Handler.Data == Value)
{
Handler.MenuItem.DefaultItem = true;
this.Text = Handler.MenuItem.Text.Replace("&", "");
return;
}
throw new ArgumentOutOfRangeException(
"Value", Value, "The value is not is the list of acceptable values.");
}
P.S. One more bizarre thing, if I put (Handler.Data == Value) in a watch
window and step through the routine, the window indicates that the
expression evaluates to true for the appropriate iteration, but the code
within the if block still does not run. Could this be a C# bug?
--Ken