Changing property type in class that implements interface with object type property

前端 未结 3 1417
臣服心动
臣服心动 2021-01-18 16:48

I\'m writing a TemplateEngine that will allow me to use my own markup in text based files. I\'m wanting to add controls as plugins as the application matures. Currently i\'v

3条回答
  •  清酒与你
    2021-01-18 17:33

    Normally the Repeater would implement something different, like an IItemsControl for example.

    EDIT 1

    (removed for brevity)

    EDIT 2

    Ah okay, you can always use explicit interface implementation of course:

    interface IControl
    {
        string Id { get; set; }
        object Value { get; set; }
    }
    
    class Label : IControl
    {
        public string Id { get; set; }
        public string Value { get; set; }
    
        object IControl.Value
        {
            get { return this.Value; }
            set { this.Value = (string)value; }
        }
    }
    
    class Repeater : IControl
    {
        public string Id { get; set; }
        public IList Value { get; set; }
    
        object IControl.Value
        {
            get { return this.Value; }
            set { this.Value = (IList)value; }
        }
    }
    

提交回复
热议问题