0

How can I order PropertyInfos? I have a class:

public class Test
{
    public int Number { get; set; }

    public string Text { get; set; }

    public bool IsActive { get; set; }

    public File File { get; set; }
}

And I get the properties using typeof(Test).GetProperties();

How can I order them by type? Example:

typeof(Test).GetProperties().OrderBy(new List<Type>()
{
    typeof(File),
    typeof(string),
    typeof(int),
    typeof(bool)
});

So result will be :

File, Text, Number, IsActive

If there was a different list of hints, the result should also be changed.

Can it be done?

Florian
  • 1,019
  • 6
  • 22
  • 1
    See this answear about it: https://stackoverflow.com/a/9064293/468973 – Magnus Apr 06 '23 at 09:40
  • Your `OrderBy` parameter isn't a lambda. Assuming `OrderBy(p =>`, use `List.IndexOf` or `Array.IndexOf`: `new[] { typeof(File), typeof(string), ... }.IndexOf(p.PropertyType)`. – NetMage Apr 06 '23 at 18:27

0 Answers0