0

I have a class Project like this

class Project
{
   public int IdProyecto { get; set; }
   public string Nombre { get; set; }
   public string Descripcion { get; set; }
   public string Distrito { get; set; }
   public string Provincia { get; set; }
   public string Departamento { get; set; }
   
   public List<string> GetSetProperties ()
   {
          ///
   }
}

Project project = new Project();
project.Nombre = "Project name";
project.Distrito = "District";

Console.Write(project.GetSetProperties()); // this should print: [Nombre, Distrito];

I would like to get only the properties that were set.

can you help me?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
cantuta
  • 29
  • 1
  • 4
  • Can you show us what you've done so far? Stack Overflow is not a free code writing service. You are expected to try to write the code yourself. After [doing more research](http://meta.stackoverflow.com/questions/261592) if you have a problem you can post what you've tried with a clear explanation of what isn't working and providing a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Roman Marusyk Sep 22 '21 at 23:04
  • maybe `typeof(Project).GetProperties.Where(x => x.GetValue(project) != default)).Select(x => x.Name)`, however, you likely need to rethink this problem – TheGeneral Sep 22 '21 at 23:05
  • Hello, Roman. that is all I've done. – cantuta Sep 22 '21 at 23:05
  • 2
    If I write `project.Departamento = null`, does that count as "set"? – Jeroen Mostert Sep 22 '21 at 23:05
  • You can't determine if autoproperty was set, you can only determine if it's value is equal to default. – Guru Stron Sep 22 '21 at 23:06

0 Answers0