0

I have a class Annotations, and 2 classes that inherit from it, HousingAnnotations and AutoAnnotations

 public class Annotations
{
    public string original_posting_date { get; set; }
    public string price { get; set; }

}

public class HousingAnnotations : Annotations
{

    public string laundry_on_site { get; set; }
    public string condo { get; set; }
    public string w_d_in_unit { get; set; }
    public string street_parking { get; set; }
    public string w_d_hookups { get; set; }
    public string bedrooms { get; set; }

}

public class AutoAnnotations : Annotations
{
    public string vin { get; set; }
    public string year { get; set; }
}

What I would like to do is allow for population of either Auto or HousingAnnotation without specifying which type, for instance

AnnotationHelper annotation = new AnnotationHelper{bedrooms = "2", vin = "123"};

or something like that. Since I cannot inherit from both classes, how can I get around this? I know there are workarounds using interfaces, but I do not want to have to call out each property in my AnnotationHelper class. What are some ways to get around this?

Isaac Levin
  • 2,809
  • 9
  • 49
  • 88
  • 7
    Is there a reason you need separate classes if you're just going to use them like this anyway? – Blorgbeard Apr 12 '15 at 20:10
  • possible duplicate of [Multiple Inheritance in C#](http://stackoverflow.com/questions/178333/multiple-inheritance-in-c-sharp) – Sami Apr 12 '15 at 20:21
  • @Blorgbeard I plan on using it as an input/output class, so I can differentiate at times (giving the cient the different classes grouped) but also have them combined (when getting data based on these property values, all the data is inline and not really differentiated) – Isaac Levin Apr 12 '15 at 20:58
  • According to the comment above mine, you're just using it to pass around the classes as a whole. Why not create a struct with the classes as fields and pass that around? – Krythic Apr 12 '15 at 21:26
  • _"I plan on using it as an input/output class, so I can differentiate at times"_ -- sounds like a perfect use case for interfaces. Alternatively, just use composition and have the class expose the contained instances of the two different classes. – Peter Duniho Apr 12 '15 at 21:46

0 Answers0