Search code examples
c#visual-studiodynamic

How to find references of a C# dynamic type property in Visual Studio


Let's say in C# I have a dynamic type variable and in some point I set multiple properties with some values, and I keep using the dynamic variable properties along all my code. How do I find all the references of one specific property of my dynamic variable using Visual Studio (2022 preferably) ? If it is not possible, what are the turnarounds if any ?

I tried, by right clicking on the property but in the references pane shows nothing, and when I try just the dynamic variable, it comes with all the references of all properties.

dynamic mySettings = someObj;
mySettings.myProp = "abc"; // <- Ex: I just want the references of myProp in the results
mySettings.myProp2 = 123;
if(mySettings.myProp == "abc"){
    mySettings.myProp = "cde";
    mySettings.myProp2 = 456;   
}

* I finished using what Guru Stron suggested (I like the options to look in specific file types like .cs) and also used the regular 'find all' option in the search dialog. At least these options show the results in the Find pane.

enter image description here

enter image description here


Solution

  • Code navigation here will not help because of the dynamic. You can try using Find in Files functionality and search either for myProp or .myProp (possibly check Match whole word and Match case options).

    enter image description here

    Also you can try limiting file types (for example to *.cs only).