10

In Typescript, there is a Pick Utility Type. Is it possible to do the same in C#? For example:

public class SomeClassA {
    public string SomePropA { get; set; }
    public string SomePropB { get; set; }
    public string SomePropC { get; set; }
}

public class SomeClassB Pick<SomeClassA, SomePropA, SomePropB> {
}
3
  • 3
    c# does not have an equivalent.
    – user47589
    Commented Apr 1, 2021 at 21:31
  • I suppose you could make this happen using C#9's Source Generators, maybe, but I don't know enough about them. I think they're still in preview.
    – user47589
    Commented Apr 1, 2021 at 23:57
  • Yeah my ViewModel (and DTO) classes are a mess of inheritance and splitting classes because you cant do this. But to be honest...who cares...the client certainly doesn't....
    – Andy
    Commented Jan 24 at 14:17

0

Browse other questions tagged or ask your own question.