Finding wrapper write access through wrapped field write access

I have a particular QoL thorn I think should be fixable but I'm looking for some guidance and insight.

In our current project we use a generic `Property<>` wrapper around all entries in our data layer, which basically contains this:

public class Property<T>
{
public T Value { get; set; }

/* ... */
}

and then we'd have like

public class EmployeeData
{
public Property<string> name = new();
public Property<int> age = new();
}

The crux is when you're looking at usages for eg `EmployeeData.name` you end up with all access being read access (`someEmployee.name.Value = "Alice"`) but I'm wondering if there's some way to inform ReSharper to instead classify write access to `.Value` as write access to the entire property, so we don't have to read every read access hit to see if it really is a write access to `.Value` (extra much cognitive load to differentiate `.Value = "Alice"` v `.Value == "Alice"` in results).

I wouldn't mind dig in to making a plug-in, however I got a bit overwhelmed last thing I tried so I thought I'd check with an expert first.

Cheers,
Tobias.

1 comment
Comment actions Permalink

Hello Tobias, thank you for your question. ReSharper doesn't have such a functionality. But creating such a plugin shouldn't be difficult - you need to add a similar component:

[SolutionComponent]
public class CustomReferencedKindProvider : ReferenceOccurrenceKindProvider, IOccurrenceKindProvider
{
  public new virtual ICollection<OccurrenceKind> GetOccurrenceKinds(IOccurrence occurrence)
  {
    if (occurrence is ReferenceOccurrence referenceOccurrence)
    {
      // detect .Value access type here using referenceOccurrence.PrimaryReference
      // return either OccurrenceKind.Read or OccurrenceKind.Write
    }
    return base.GetOccurrenceKinds(occurrence);
  }
}

Please let me know if you have any questions. Thank you!

0

Please sign in to leave a comment.