C# Get FieldInfos/PropertyInfos in the original order?

前端 未结 5 664
独厮守ぢ
独厮守ぢ 2020-12-03 13:42

How can I get a Types FieldInfos/PropertyInfos as a MemberInfo array in the order they are laid out in the class?

class Test
{
    public bool First { get; s         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 14:08

    I have found more information when trying to google the other way around. Like JbEvain pointed out, it is confirmed that there is no way to control the order in which the compiler outputs members in CIL classes. This even pertains to XmlSerializer

    A number of interesting posts have posted here:

    On that topic, I found that in fact to have reliable ordering (In .NET 2.0, you can also “explicitly“ control this using the XmlElementAttribute.Order)[pluralsight-training.net/community/blogs/tewald/archive/2006/04/… and others

    • http://www.pluralsight-training.net/community/blogs/craig/archive/2006/04/06/21176.aspx
    • http://www.pluralsight-training.net/community/blogs/craig/archive/2006/04/18/21933.aspx
    • http://www.pluralsight-training.net/community/blogs/tewald/archive/2006/04/18/21964.aspx

    This should give a good background to this discussion. It now really depends on what the original poster needed this information for whether there can even be a solution, and if so, to find a route to achieving that goal.

提交回复
热议问题