Share via


auto property accessor is never used

Question

Tuesday, July 28, 2015 6:45 PM

Resharper  gave me a warning, auto property accessor is never used.

public class LogEventInfoData
    {
      
        public Dictionary<string,string> LogEventDataDictionary { get; private set; }

        public string FileName
        {
            set
            {
                if (LogEventDataDictionary.ContainsKey("FileName"))
                    LogEventDataDictionary["FileName"] = value;
                else
                {
                    LogEventDataDictionary.Add("FileName",value);
                }
            }
        }

        public string StationId
        {
            set
            {
                if (LogEventDataDictionary.ContainsKey("StationID"))
                    LogEventDataDictionary["StationID"] = value;
                else
                {
                    LogEventDataDictionary.Add("StationID", value);
                }
            }
        }
        public LogEventInfoData(string fileName,string stationId)
        {
            FileName = fileName;
            StationId = stationId;
        }
    }

Should I ignore it or refactor it?

All replies (1)

Tuesday, July 28, 2015 7:05 PM âś…Answered

It is clear which one is not used. But even if it is not used now, perhaps it will be used in the next version of other projects.

Also consider this possible modification of accessors:

public string FileName

{

       set { LogEventDataDictionary["FileName"] = value; }

}

public string StationId

{

       set { LogEventDataDictionary["StationID"] = value; }

}

Looks more elegant.

Also make sure that the dictionary is not null. Or even replace it with something else, like two separate strings.