none
Debugging {get ; set; } RRS feed

  • Question

  • Hi,

    Am new to C# and am debugging an existing very old C# application where there is {get ; set;} happening as below within a Class

    public string   XYZ {get ;set;}

    When I searched the entire .sln solution, there is nowhere I could find the source code of the method XYZ

    In any programming language, being able to see the source code is the fundamental thing, which am not able to in this context.   Is it possible that the functionality of the XYZ method is made into a .dll kind of unreadable content, and the actual source code is missing from the .sln ? However, it doesn't seem so - because , I am able to open the entire .sln solution in Visual Studio.

    What are the tips of debugging this XYZ method, to locate its code?  The breakpoint on this line is not helping even with Stepover/Stepinto features

    many thanks

    Sunday, November 10, 2019 10:30 PM

All replies

  • I believe VS2019 you can right click and select "Go to definition" and it will decompile to the source while with any version of Visual Studio ReSharper (paid tool) will decompile source code from an available assembly. 

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, November 10, 2019 11:59 PM
    Moderator
  • Greetings etl2016.

    There isn't really any source code for that method. What you see is it. Well, there is, technically, but you don't need to know about it.

    In older versions of c#, such a method would be written something like the following.

    string xyz;
    public string XYZ{get{return xyz;} set{xyz = value;}}

    So the 'get' and the 'set' do just that - they get or set a property, respectively.

    In not-so-old c#, (such as the code that you posted) the compiler will create a 'backing field' for you (the lower-case xyz) and then essentially do the same thing - just get it and set it. So there's really nothing to debug into (unless you have reason to suspect a bug in the compiler).

    • Proposed as answer by cheong00Editor Monday, November 11, 2019 1:54 AM
    Monday, November 11, 2019 12:49 AM
  • This is a declaration of an auto-implemented property. The actual implementation is generated by the compiler, basically a getter and a setter method backed up by a field. In debug options you get to choose whether you want to step over a property. But it's designed for handwritten property setters and getters, I am not sure what is the point of even stepping into compiler generated property. Those are too simple to have bugs. 


    Visual C++ MVP

    • Proposed as answer by cheong00Editor Monday, November 11, 2019 1:54 AM
    Monday, November 11, 2019 1:10 AM
  • public properties use get/set with a private backing vaiable for a given public property.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties

    The get/set you have posted it about is an auto property that has a private backing vaibale assigned by the compiler.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties

    Do you really need to waste your time on debugging an auto property?

    • Proposed as answer by cheong00Editor Monday, November 11, 2019 1:54 AM
    Monday, November 11, 2019 1:49 AM
  • Looking at other replies, there is the possibility that etl2016 is looking at meta data which might have code behind that is not seen for example the following may show

    public string Position { get; set; }

    But have much more.

    public string Position
    {
        get
        {
            if (Contact != null)
            {
                var validStudentTypes = new List<string>
                {
                    "Appraiser",
                    "Appraiser Manager",
                    "Appraiser Trainee",
                    "Other"
                };
    
    
                return Contact.ContactContactTypes
                        .Where(cct => validStudentTypes.Contains(cct.ContactType.ContactTypeName))
                        .OrderBy(cct => cct.ContactType.ContactTypeName)
                        .FirstOrDefault()
                        ?.ContactType.ContactTypeName;
            }
            else { return ""; }
        }
        set { _Position = value; }
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, November 11, 2019 2:39 AM
    Moderator
  • Thank you Karen and everyone for your replies.    Karen - yes, that's exactly what I am looking for.  There seems to be business logic associated with XYZ in   public string   XYZ {get ;set;} 

    There is a namespace/enum file within .sln solution that lists various values, however, how a selection of these various possible values is happening - is the core of my research, but, this logic/code is not found yet.

    Right-clicking XYZ and opting for "Go to Definition"  or  "Peek Definition" is not showing any code/business-logic associated with this getting/setting.  Even putting a breakpoint and opting for Stepinto/StepOver is not helpful.

    thanks

    Monday, November 11, 2019 8:58 AM
  • Why wouldn't you just search/fine for the variable in the solution? If it's not used then it's not used, which can happen sometimes. 
    • Edited by DA924x Monday, November 11, 2019 1:39 PM
    Monday, November 11, 2019 1:39 PM
  • In that case you'll probably want to search for "public new string XYZ"and see if that "business logic" is supplied by a inheriting class overriding the default property.

    You've not specified the nature of the class which contains the property. If this is for temporarily holding data (say, database POCO classes, or certain UI state variables), it's also common to apply the business logic when "Save" or "DoWhatever" is invoked.

    Tuesday, November 12, 2019 1:15 AM
    Answerer