Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Property Get Runs When Class Instantiated
Message
From
09/04/2009 17:44:59
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
09/04/2009 17:01:43
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01394040
Message ID:
01394067
Views:
39
>Change the _colClients variable name to something else and recompile. The errors should show you everything that is referencing it.
>

Jeez Mike you are smarter than you look! I didn't think of that. (just kidding, but it was a good idea). It was pretty interesting since his class is private and there is only two references to the private field.
Tim

>>The breakpoint stops the code when the field is initialized during instantiation, but the count is 0. When I step out of all the private field initializations, the count is 3. At no time does _LoadClients(); get called.
>>
>>
>>>Set your breakpoint on _colClients. Since it is read only you are also setting the underlying variable from other places. If _LoadClients is being called from anywhere it is also setting the value. by the way, it appears you class is private so the read only property isn't really available outside the class. I wish VS would make classes public by default from the template. One day I will fix this again in my install.
>>>Tim
>>>
>>>>Here is the class:
>>>>
>>>>
>>>>class csCompany : csDataRecordBase
>>>>{
>>>>    private ArrayList _colClients = new ArrayList();
>>>>    public ArrayList colClients
>>>>    {
>>>>        get
>>>>        {
>>>>            if (_colClients.Count == 0)
>>>>            {
>>>>                _LoadClients();
>>>>            }
>>>>            return _colClients;
>>>>        }
>>>>    }
>>>>    
>>>>    private string _sCompanyName = "";
>>>>    public string sCompanyName
>>>>    {
>>>>        get { return _sCompanyName; }
>>>>        set { _sCompanyName = value; }
>>>>    }
>>>>
>>>>    public override bool LoadData()
>>>>    {
>>>>        bool bRetVal = true;
>>>>        SqlDataReader rdrReader = csAppDataAccess.GetCompany(this.iRecordId);
>>>>
>>>>        if (csAppDataAccess.oException == null)
>>>>        {
>>>>            rdrReader.Read();
>>>>            _sCompanyName = rdrReader["CompanyName"].ToString();
>>>>        }
>>>>        else
>>>>        {
>>>>            this.oException = csAppDataAccess.oException;
>>>>            bRetVal = false;
>>>>        }
>>>>
>>>>        return bRetVal;
>>>>    }
>>>>
>>>>
>>>>    private void _LoadClients()
>>>>    {
>>>>        _colClients.Clear();
>>>>
>>>>        csClients oClients = new csClients();
>>>>        oClients.LoadData(this.iRecordId);
>>>>        _colClients = oClients.colData;
>>>>    }
>>>>
>>>>
>>>>}
>>>>
>>>>
>>>>And here's the instantiation:
>>>>
>>>>
>>>>csCompany oCompany = new csCompany();
>>>>
>>>>
>>>>When I hover over oCompany and expand the tooltip, colClients shows "Count = 3"
>>>>
>>>>I have no idea why.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>>I have a property on a Company class:
>>>>>>
>>>>>>
>>>>>>private ArrayList _colClients = new ArrayList();
>>>>>>public ArrayList colClients
>>>>>>{
>>>>>>    get
>>>>>>    {
>>>>>>        if (_colClients.Count == 0)
>>>>>>        {
>>>>>>            _LoadClients();
>>>>>>        }
>>>>>>        return _colClients;
>>>>>>    }
>>>>>>}
>>>>>>
>>>>>>
>>>>>>When I instantiate the class, the colClients collection is being loaded. I put a breakpoint on the IF() inside the Get, but it doesn't break. Yet when I look at colClients.Count, it's set to 3 instances of a Client class.
>>>>>>
>>>>>>Anyone know why the Get assesor is firing when the class is instantiated?
>>>>>
>>>>>Search your class for any references to "colClients".
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform