Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created September 15, 2023 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jskeet/7540086d73d27561670bba3193e642ce to your computer and use it in GitHub Desktop.
Save jskeet/7540086d73d27561670bba3193e642ce to your computer and use it in GitHub Desktop.
List<Quantite> list = new List<Quantite>
{
new Quantite
{
Poids = 0,
Palette = 33,
UniteSpecifique = "test"
}
};
foreach (var quant in list)
{
var quantite = quant.GetType()
.GetProperties()
.Select(x => new { nom = x.Name, value = x.GetValue(quant), type = x.PropertyType })
.ToList();
foreach (var property in quantite)
{
if (property.type == typeof(int?))
{
Console.WriteLine($"{property.nom} has type int?");
}
else if (property.type == typeof(string))
{
Console.WriteLine($"{property.nom} has type string");
}
else if (property.type == typeof(decimal?))
{
Console.WriteLine($"{property.nom} has type decimal?");
}
// etc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment