Users Pricing

forum

Home Forums Polymorphism on c# property – MindStick

Polymorphism on c# property

Anonymous User 2338 28 Aug 2014

I have a class like this:

public class ItemField
{
    public string FieldName { get; set; }
    public object FieldValue
    {
        get;
        set;
    }
}

I want to have it so that "FieldValue" can only be of type string, MyItem, or List<MyItem>. I also want it so that when code consumes this class, accessing "FieldValue" returns the right type of object. Is there a way to do this? I'm not too clear on generics, but there seems to be a way to do this using that.


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md