Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve ReSharper's "unused property" warning on properties solely for Display/Value Members?

I have defined two properties, "Name" and "ID", for an object which I use for the DisplayMember and ValueMember of a ComboBox with a BindingList datasource.

I recently installed ReSharper to evaluate it. ReSharper is giving me warnings on the object that the two properties are unused.

Sample code:

BindingList<ClassSample> SampleList = new BindingList<ClassSample>();
// populate SampleList
cmbSampleSelector.DisplayMember = "Name";
cmdSampleSelector.ValueMember = "ID";
cmbSampleSelector.DataSource = SampleList;

private class ClassSample
{
    private string _name;
    private string _id;

    public string Name // ReSharper believes this property is unused
    {
        get { return _name; }
    }

    public string ID // ReSharper believes this property is unused
    {
        get {return _id; }
    }

    public ClassSample(string Name, string ID)
    {
        _name = Name;
        _id = ID;
    }
}

Am I doing something wrong or is ReSharper clueless about this particular usage?

like image 319
JYelton Avatar asked Jun 17 '10 17:06

JYelton


1 Answers

The way that JetBrains suggests that you solve these issues is with their attributes (available from ReSharper -> Options -> Code Annotations). Add the attributes to your project/solution and then mark these properties with the UsedImplicitly attribute. ReSharper will now assume that the properties are used via Reflection or late bound or whatever.

like image 179
David Williams Avatar answered Sep 28 '22 03:09

David Williams