Removing accessories from an item

Enter the following class:

public Person
{
 public string Name {get; set;}
 public string Age {get; set; }
}

If I wanted Return then, IList will return the list anyway, will there be all IList functionality, but with remote setters? Perhaps using an extension method to remove setters. I would suggest that you have to use reflection, but is this the only way to do this? Will it be feasible in terms of speed / implementation.

I'm just wondering how this can be done, this is not a real design. And I know that I simply return IEnumerable or IEnumerable with a pass or yield that would solve this problem.

thank

+3
source share
2 answers

with setters removed from Person class? create

IReadonlyPerson
{
  string Name { get; }
  string Age { get; }
}

( ), IList. IList @RPM1984.

+5
+1

Source: https://habr.com/ru/post/1772560/


All Articles