I have developed a set of routines to compute certain statistics.
Because some of these computations are rather involved, I have
designed the relevant properties so that a statistic is computed the
first time it is encountered, that value is saved, and the previously
saved value is retrieved the next time the relevant property is
accessed.
A simple example: The Total property returns the total of a set of
numbers. The first time the Total property is evaluated, the numbers
are added together, and the result is stored. The next time the Total
property is accessed, the previously computed result is returned. Here
is the code --
public double Total
{
get
{
if (!total.IsComputed)
{
SET BREAKPOINT HERE => total.Value = 0.0d;
foreach(double d in dataList)
{
total.Value += d;
}
total.IsComputed = true;
return total.Value;
}
else return total.Value;
}
set
{
total.IsComputed = true;
total.Value = value;
}
}
The problem is that if I set a breakpoint in the code where
total.Value is first computed and then run the debugger, the debugger
never reaches the breakpoint because Visual Studio has already
evaluated the property Total. When I step through the program, the
debugger always evaluates total.IsComputed as "true" and skips to the
"else return total.Value" statement.
Is there any way, by means of an attribute or otherwise, the prevent
Visual Studio from evaluating the Total property until the program is
running in the debugger?
James Westgate [Crainiate] - 09 Jun 2004 22:11 GMT
Possibly change the Total property to GetTotal and SetTotal method calls?
James

Signature
Create interactive diagrams and flowcharts with ERM Diagram at
http://www.crainiate.net
Take the ERM Tour at http://www.flowchartcontrol.com
> I have developed a set of routines to compute certain statistics.
> Because some of these computations are rather involved, I have
[quoted text clipped - 42 lines]
> Visual Studio from evaluating the Total property until the program is
> running in the debugger?
Marc Scheuner [MVP ADSI] - 10 Jun 2004 08:38 GMT
>I have developed a set of routines to compute certain statistics.
>Is there any way, by means of an attribute or otherwise, the prevent
>Visual Studio from evaluating the Total property until the program is
>running in the debugger?
Yes - if you descend from System.ComponentModel.Component. It features
a protected boolean property called "DesignMode" which indicates
whether or not the component is currently in design mode or not.
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
DRaiko - 11 Jun 2004 09:38 GMT
Hallo,
I see only one reason for the flag .IsComputed to be set to "true":
(i) The .Total is accessed at design time (i.e. just after you
put the component on a form and maybe inspect its props in
the prop window) and computed setting the flag.
(ii) the flag value is persisted and restored (thus geting the value
"true") when you start the application.
To check: expand the generated code section and look what is assigned
to the IsComputed property (there must be
this.<component>.IsComputed = true;
in InitializeComponents).
To break the chain you can, for instance, prevent the property
serialization. This would be reasonable: The flag may not remember
the value it has had in its "previous life" (at design time) in
contrast to other properties (like .Top, .Left, etc., that must
preserve the values thay get when you design a form).
To do this you can split the property in two methods (GetIsComp
+ SetIsComp), so that the serializer has no chance to anderstand
how to serialise the value behind the names,
or you can forbid serialization explicitely with the
DesignerSerialisationVisabilityAttribute(
DesignerSerialisationVisability.Hidden)
Seams to me.
HTH,
Dima.
> I have developed a set of routines to compute certain statistics.
> Because some of these computations are rather involved, I have
[quoted text clipped - 42 lines]
> Visual Studio from evaluating the Total property until the program is
> running in the debugger?