Give the following class:
public Person
{
public string Name {get; set;}
public string Age {get; set; }
}
If I wanted to then Return a IList is there anyway to return the List will all the Functionality of an IList but with the setters removed? Possibly with an extension method to remove the setters. I would Imagine you would have to use reflection but is this the only way that this could be done? Would it be feasible from a speed/implementation point of view.
I was just wondering how this could be done, it is not an actual design. And I am aware of just returning an IEnumerable, or IEnumerable with a skip or yield that would solve for this problem.
Thanks
with the setters removed from the Person class? create
IReadonlyPerson
{
string Name { get; }
string Age { get; }
}
have Person implement it (it already does), then return a IList. if you are talking about the mutability of the IList look at @RPM1984's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With