Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 939823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:51:12+00:00 2026-05-15T21:51:12+00:00

A familiar problem using VisualStudio is the mysterious calling of property getters. If these

  • 0

A familiar problem using VisualStudio is the mysterious calling of property getters. If these have side effects (the most common being of the form if (foo == null) foo = new foo(); return foo; ), then the fact that the debugger Locals and Watch windows call the properties – without even hitting any break points – can lead to unexpected effects when debugging.

There is a simple solution to this: just tag the property with the attribute

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]

So how can I find getters which may have side effects in a large code base?

NDepend is the tool of choice for this kind of thing: using its CQL language I can find all the properties which, for example, directly change the state of their containing instance:

         SELECT METHODS FROM ASSEMBLIES "FOO" 
         WHERE IsPropertyGetter AND ChangesObjectState 

This only finds those getters which change a field directly: how can I find ones which change it indirectly, e.g. by calling an Initialize() method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:51:13+00:00Added an answer on May 15, 2026 at 9:51 pm

    Joel, this is possible thanks to Code Query through LINQ capabilities (CQLinq). Here is a CQLinq query that detect deep mutability for property getters. For each getters that provokes mutability, the code query shows the set of fields assigned.

    // Restrict the iteration only on property getters
    // that are changing states or that call a method that changes state
    let propertyGetters = Application.Methods.Where(m => m.IsPropertyGetter)
    
    let methodsThatChangeState = 
      Application.Methods.Where(m => m.ChangesObjectState || m.ChangesTypeState)
    
    from m in propertyGetters.DepthOfIsUsingAny(methodsThatChangeState).DefinitionDomain
              .Union(propertyGetters.Intersect(methodsThatChangeState))
    
    // Find all methods called directly or indirectly by the property getter
    let methodsCalledIndirectly = 
            m.MethodsCalled.FillIterative(
               methods => methods.SelectMany(m1 => m1.MethodsCalled))
            .DefinitionDomain
            .Union(m.ToEnumerable())
    
    // Gather all field assigned that are not generated by the compiler
    let fieldsAssigned = methodsCalledIndirectly
                         .SelectMany(m1 => m1.FieldsAssigned)
                         .Where(f => !f.IsGeneratedByCompiler)
    
    where fieldsAssigned.Any()
    orderby fieldsAssigned.Count() descending 
    select new { m, fieldsAssigned }
    

    This query is complex, mainly because I optimized it, to first keep only getters that themselves changing state, or that are calling directly or indirectly a method that is changing state (call to DepthOfIsUsingAny()).

    Then, for each of this getter, we build the set of all methods called directly or indirectly (thanks to a call to FillIterative()), and we gather all fields assigned by all this method.

    Concretely the query result looks like:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm familiar with using NSLocalizedString() to localize strings, but the problem I have today
I'm trying to get familiar with CI and I have run into a problem
i'm using jquery Ui slider for a web-project, and i have a small problem,
I have problem with my web application. I am using MVC3 and not so
I have a problem using openCV 2.3.1 installed from mac ports. For installation and
I'm trying to get familiar with ViewPager. My code is given below. The problem
People familiar with Homographies will know that you have to normalize it dividing by
I am familiar with using preceding axes in XSLT for finding determining the number
I am not terribly familiar with either tech, so bear with me. I have
I’m having a problem trying to detect if a table exists using jQuery. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.