none
To find out which properties of a given class are in use in different solutions

    Question

  • Hi,

    My requirement is : to find out which properties of a given class are in use  in different solutions and  how those are used(basically to retrieve the line of code so that we get to know the logic).

    I am given  Seven Visual studio solutions and a class with some properties.
    I need to go to every solution and  loop through every property of the given class and find out,

    1. The line of code where this property is used.
    2. The Method name in which the property is utilized.
    3. The Class Name in which this method exists.
    4. The project in which  this class exists.


    And I need to store this information in a file. For Example in a Microsoft Excel document.
    I need to do the above steps for all the variables  of the given input class.

    Can you please help me how to achieve this? Can you please  suggest some tools or an algorithm to implement this.

    The class which I am given has over 100 properties, and these properties can be enums(I saw one enum has 40 values) and other class instances also. So I need to find out in all the given seven different solutions, where all the properties in the given class are used..in the format, propertyName, code where this property is used(1 or 2 lines), method Name, className and the project Name. If possible Can you please suggest an algorithm(so that I can try to develop a tool) or any tools available? The basic requirement is to find out which fields are actually used in the given 7 solutions. I need to create a file with these details.

    Please let me know if you need more information.

    Thanks,

    Siddi.


    Siddi Khadar Vali Pothuganti


    • Moved by Kristin Xie Thursday, December 24, 2015 3:10 AM move to better forum
    • Edited by siddi4 Thursday, December 24, 2015 4:50 AM Adding more information regarding the number of properties
    Wednesday, December 23, 2015 4:14 PM

Answers

  • Unless you had to do this for a lot of classes then the manual approach will be much more practical.

    If the method names are common ones then visual studio ultimate gives you the "references" above each of the methods.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Marked as answer by siddi4 Monday, December 28, 2015 5:08 AM
    Wednesday, December 23, 2015 7:11 PM
  • Thank you Andy, The class which I am given has over 100 properties, and these properties can be enums(I saw one enum has 40 values) and other class instances also. So I need to find out in all the given seven different solutions, where all the properties in the given class are used..in the format, propertyName, code where this property is used(1 or 2 lines), method Name, className and the project Name. If possible Can you please suggest an algorithm(so that I can try to develop a tool) or any tools available? The basic requirement is to find out which fields are actually used in the given 7 solutions. I need to create a file with these details.

    Thanks,

    Siddi.


    Siddi Khadar Vali Pothuganti

    This is going to be a tricky one to automate. In fact I don't see how you can. Maybe you should push back on this requirement.

    ,

    I think manual searching might well be more practical.

    Say you used powershell to automate visual studio searching.

    http://blogs.msdn.com/b/stuartleeks/archive/2014/03/19/scripting-visual-studio-with-powershell-great-for-demos.aspx

    You'd need to extract a list of things to search on to feed into this script.

    You could use reflection to get the properties and methods.

    For example, this iterates all properties in a type in order to do a generic equality comparison:

                foreach (System.Reflection.PropertyInfo property in t.GetProperties())
                {
                    if (property.Name != "ExtensionData")
                    {
                        string OldValue = string.Empty;
                        string NewValue = string.Empty;
                        if (t.GetProperty(property.Name).GetValue(newObj, null) != null)
                        {
                            OldValue = t.GetProperty(property.Name).GetValue(newObj, null).ToString();
                        }
                        if (t.GetProperty(property.Name).GetValue(oldObj, null) != null)
                        {
                            NewValue = t.GetProperty(property.Name).GetValue(oldObj, null).ToString();
                        }
                        if (OldValue.Trim() != NewValue.Trim())
                        {
                            return true;
                        }
                    }
                }
                return false;
            }
    You could use a similar approach to get the names of all those methods.

    .

    There are a number of problems you're going to have with this.

    Say you have a GetData method in your class.

    If you search on GetData then you will find any instance of that in your code.

    Should that be used in 10 different classes you will get them as well.

    You're going to have to look at any results manually.

    .

    I hope whoever gave you this task understands just how long you're going to need to gather this data.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Friday, December 25, 2015 11:21 AM
  • Hi Siddi,

    >>I need to go to every solution and  loop through every property of the given class and find out,

    1. The line of code where this property is used.
    2. The Method name in which the property is utilized.
    3. The Class Name in which this method exists.
    4. The project in which  this class exists.

    To find all name like the above requirements, it seems that it is hard in the default VS IDE.

    We often use the Find and Replace window window in default VS IDE to search one variable/parameter in the whole solution.

    And then it would share us the result like this screen shot:

    Even if it doesn't share all the results you want to get, but as my understanding, it would be a better workaround in the default VS IDE now.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 25, 2015 6:35 AM
    Moderator

All replies

  • I suggest  that  you use VS's IDE Find All on an entire solution and copy/paste the results  into a spreadsheet.

    Trying to come up with anything else is just a little too ridiculous.

    Wednesday, December 23, 2015 5:54 PM
  • Unless you had to do this for a lot of classes then the manual approach will be much more practical.

    If the method names are common ones then visual studio ultimate gives you the "references" above each of the methods.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Marked as answer by siddi4 Monday, December 28, 2015 5:08 AM
    Wednesday, December 23, 2015 7:11 PM
  • Thank you Andy, The class which I am given has over 100 properties, and these properties can be enums(I saw one enum has 40 values) and other class instances also. So I need to find out in all the given seven different solutions, where all the properties in the given class are used..in the format, propertyName, code where this property is used(1 or 2 lines), method Name, className and the project Name. If possible Can you please suggest an algorithm(so that I can try to develop a tool) or any tools available? The basic requirement is to find out which fields are actually used in the given 7 solutions. I need to create a file with these details.

    Thanks,

    Siddi.


    Siddi Khadar Vali Pothuganti

    Wednesday, December 23, 2015 7:51 PM
  • Hi siddi4,

    This forum is discussing about the C# development, as your issue is more related to the VS itself, we help you move it to the Visual Studio General Questions forum for better support.

    Thank you for your understanding.

    Best Regards,

    Albert Zhang

    Thursday, December 24, 2015 3:08 AM
  • Hi Siddi,

    >>I need to go to every solution and  loop through every property of the given class and find out,

    1. The line of code where this property is used.
    2. The Method name in which the property is utilized.
    3. The Class Name in which this method exists.
    4. The project in which  this class exists.

    To find all name like the above requirements, it seems that it is hard in the default VS IDE.

    We often use the Find and Replace window window in default VS IDE to search one variable/parameter in the whole solution.

    And then it would share us the result like this screen shot:

    Even if it doesn't share all the results you want to get, but as my understanding, it would be a better workaround in the default VS IDE now.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 25, 2015 6:35 AM
    Moderator
  • Thank you Andy, The class which I am given has over 100 properties, and these properties can be enums(I saw one enum has 40 values) and other class instances also. So I need to find out in all the given seven different solutions, where all the properties in the given class are used..in the format, propertyName, code where this property is used(1 or 2 lines), method Name, className and the project Name. If possible Can you please suggest an algorithm(so that I can try to develop a tool) or any tools available? The basic requirement is to find out which fields are actually used in the given 7 solutions. I need to create a file with these details.

    Thanks,

    Siddi.


    Siddi Khadar Vali Pothuganti

    This is going to be a tricky one to automate. In fact I don't see how you can. Maybe you should push back on this requirement.

    ,

    I think manual searching might well be more practical.

    Say you used powershell to automate visual studio searching.

    http://blogs.msdn.com/b/stuartleeks/archive/2014/03/19/scripting-visual-studio-with-powershell-great-for-demos.aspx

    You'd need to extract a list of things to search on to feed into this script.

    You could use reflection to get the properties and methods.

    For example, this iterates all properties in a type in order to do a generic equality comparison:

                foreach (System.Reflection.PropertyInfo property in t.GetProperties())
                {
                    if (property.Name != "ExtensionData")
                    {
                        string OldValue = string.Empty;
                        string NewValue = string.Empty;
                        if (t.GetProperty(property.Name).GetValue(newObj, null) != null)
                        {
                            OldValue = t.GetProperty(property.Name).GetValue(newObj, null).ToString();
                        }
                        if (t.GetProperty(property.Name).GetValue(oldObj, null) != null)
                        {
                            NewValue = t.GetProperty(property.Name).GetValue(oldObj, null).ToString();
                        }
                        if (OldValue.Trim() != NewValue.Trim())
                        {
                            return true;
                        }
                    }
                }
                return false;
            }
    You could use a similar approach to get the names of all those methods.

    .

    There are a number of problems you're going to have with this.

    Say you have a GetData method in your class.

    If you search on GetData then you will find any instance of that in your code.

    Should that be used in 10 different classes you will get them as well.

    You're going to have to look at any results manually.

    .

    I hope whoever gave you this task understands just how long you're going to need to gather this data.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Friday, December 25, 2015 11:21 AM
  • Thank you Andy, DA924,Jack-Zhai  and Albert_Zhang..Thank you all for your valuable time and helping me on this..Have a good Day.

    Thanks,

    Siddi.


    Siddi Khadar Vali Pothuganti

    Friday, December 25, 2015 1:23 PM