0

This is a scenario I come across all the time. I want all the public properties to be assigned in the ctor but just lower case the first letter. Is there a method to do this?

class User
{
    public int ID { get; }
    public string Name { get; }
    public string Initials { get; }
    public DateTime LastLogOn { get; }
    public Role Role { get; }
    public User (int ID, string name, string initials, DateTime lastLogOn, Role role)
    {
        Name = name;
        Initials = initials;
        LastLogOn = lastLogOn;
        Role = role;
    }
}
paparazzo
  • 44,497
  • 23
  • 105
  • 176
  • Resharper is good for this, though not free. – Ben Aaronson Aug 04 '17 at 16:37
  • Resharper does this? I have a similar annoyance with constructors I want it to auto generate a private readonly ISomeInterace _someInterface property and in the constructor where injected set _someInterface = . Always type this and I am lazy ;-) – Shawn Aug 04 '17 at 16:38
  • I believe in VS 2017 you can [CTRL] + [.] on a constructor parameter with the same name as a property and it will add it to the body. – Dustin Kingen Aug 04 '17 at 16:40
  • 2
    I am surprised this is not considered a programming question. – paparazzo Aug 04 '17 at 16:41
  • 3
    @Paparazzi My guess is that the phrase "is there a tool" is setting off many peoples' close-vote radar. – BJ Myers Aug 04 '17 at 16:47
  • 2
    Possible duplicate of [How do I generate a constructor from class fields using Visual Studio (and/or ReSharper)?](https://stackoverflow.com/q/2976363/2137382). – Joe Sewell Aug 04 '17 at 16:56
  • @JoeSewell Changed to method – paparazzo Aug 04 '17 at 16:57
  • @JoeSewell I agree with the duplicate. This question should be closed as duplicate instead of off-topic. – Dustin Kingen Aug 04 '17 at 16:59
  • Long lists of constructor parameters considered harmful. Please consider a fluent API instead. – hoodaticus Aug 04 '17 at 17:25

0 Answers0