Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find all places that SET a property?

It is easy to find all code that uses a property, however how do I find the code that just sets it?

(When I do a “find all reference” on the “set”, it just does a “find all reference” on the property itself, including code that just reads it.)

like image 536
Ian Ringrose Avatar asked May 23 '11 10:05

Ian Ringrose


People also ask

What is a property C#?

Property in C# is a member of a class that provides a flexible mechanism for classes to expose private fields. Internally, C# properties are special methods called accessors. A C# property have two accessors, get property accessor and set property accessor.

How can you add a custom property to a form?

On the menu bar, choose View > Properties Window. The Property Editor dialog box appears. In the text box in the Name column, specify the name of the property. For the Type field of the custom property, choose the appropriate data type.

Why we use get set property in C#?

A get property accessor is used to return the property value, and a set property accessor is used to assign a new value. In C# 9 and later, an init property accessor is used to assign a new value only during object construction. These accessors can have different access levels.


3 Answers

You can use Resharper.

Alternately, set the setter to private (Or comment out the setter completely) and recompile. You will get errors where you're trying to set the property.

like image 94
Kamyar Avatar answered Oct 19 '22 14:10

Kamyar


For what it's worth, this will be natively possible with VS2019.

Specifically the 'Find All References' window has a new 'Kind' column which can be filtered for 'Write' references:

enter image description here

The specific Github PR that added this feature is scheduled to be included in Visual Studio 2019 Preview 2 (16.0.P2) https://github.com/dotnet/roslyn/issues/22545

The full release of VS2019 is roadmapped for Q1 of 2019.

like image 49
Johannes Avatar answered Oct 19 '22 13:10

Johannes


Try commenting the set part of property and build it gives error at all the places where it is used.

like image 20
Umesh CHILAKA Avatar answered Oct 19 '22 13:10

Umesh CHILAKA