本文介绍了C#获取原始顺序FieldInfos / PropertyInfos?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到一个类型FieldInfos / PropertyInfos作为它们在类中规定的顺序的MemberInfo阵列?



 类测试
{
公共BOOL首先{搞定;组; }
公众诠释秒;
公共字符串三{搞定;组; }
}


解决方案



http://msdn.microsoft.com/en-us/library/kyaxdd3x.aspx

You would need to define order yourself, perhaps with attributes:

class Test
{
    [Order(1)] public bool First { get; set; }
    [Order(2)] public int Second;
    [Order(3)] public string Third { get; set; }
}
...
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, 
    Inherited = true, AllowMultiple = false)]
[ImmutableObject(true)]
public sealed class OrderAttribute : Attribute {
    private readonly int order;
    public int Order { get { return order; } }
    public OrderAttribute(int order) {this.order = order;}
}

这篇关于C#获取原始顺序FieldInfos / PropertyInfos?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 18:50