How to inherit IReadOnly correctly?


I’m creating a custom object to save, and use, on PriceList.CustomData. This custom class needs to inherit from IReadOnly. How to use MakeReadOnly and MakeWritableClone methods?

This is what I got right now:

public class PriceListCustomDataVariantList : IReadOnly
    public List<PriceListCustomDataVariantItem> VariantList { get; set; }

    public bool IsReadOnly => false;

    public void MakeReadOnly()
    { }

    public object MakeWritableClone()
        return null;

Litium version: 7.1.0

I need to use MakeWriteableClone on this custom ireadonly class. How to implement that function correctly? Now I return null but that obviously don’t work.

You can inherit from ObjectBase class instead.

ObjectBase doesn’t give me access to MakeWriteableClone.

public class PriceListCustomDataVariantList : ObjectBase

Aha you want to override that?

Yes, I would like that. I don’t know how the standard implementation of MakeWriteableClone looks like because IReadOnly is in the Litium-assembly.

If we take VariantService.Get() for example, it has the MakeWrieableClone method that returns a Variant object. I want to do the exact same thing in my custom class.

You need to add Type also:

    public class A : ObjectBase<A>
        private IList<string> _list = new List<string>();
        public IList<string> List { get => _list; set => _list = this.ThrowIfReadOnly(value); }

    public class B
        public B()
            var a = new A();

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.