0

I'm using a public API. One of the types has a property that is an array of a base class that needs to be populated with its derived classes (uniquely and one of each derived class).

How would I go about that?

addresses = new AddressInfo[]
{
    new PhoneInfo{Number= "111-111-1111", Type = "Home"},
    new EmailAddressInfo {MailTo = "home@email.com", Type = "Home"},
    new MailingAddressInfo {Street = "101 Champagne Ave", City = "Los Angeles", State= "CA", Country = "US", Type = "Home"}
}
Tatranskymedved
  • 4,194
  • 3
  • 21
  • 47
Nomnom
  • 4,193
  • 7
  • 27
  • 37
  • What's wrong with what you have? – John Wu Nov 20 '20 at 21:09
  • What a hideous API. Are you trying to locate and instantiate the derived classes automatically? Does order matter? If you're using DI, you might be able to declare singletons for all of them and inject an `IEnumerable`. At least that would keep the mess out of your main code. – Kevin Krumwiede Nov 21 '20 at 01:58
  • What have you tried so far? This seems pretty straighforward - with Bogus you will be instantiating derived classes (`PhoneInfo`, `EmailAddressInfo`, etc..). I don't see any problem in that? – Tatranskymedved Jan 25 '21 at 20:59

0 Answers0