Created
September 15, 2023 18:47
-
-
Save jskeet/7540086d73d27561670bba3193e642ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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