add a class: 

public class ExportAttribute : Attribute
{
    public int FieldOrder { get; set; }
    public ExportAttribute() { } } add [ExportAttribute(FieldOrder = 2)] on the Field
 [DisplayName("Department Name")]
 [ExportAttribute(FieldOrder = 2)]
 public string DepartmentName {
     get {
         return this.Department.DepartmentName;
     }
 } Get the class's filed those have the DisplayName Attribute and order by the FieldOrder DisplayName
public PropertyInfo[] GetPropertyInfoArray(Type type)
       {
           PropertyInfo[] props = null;
           try
           {
               object obj = Activator.CreateInstance(type);
               //props = (from r in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
               //         where r.GetCustomAttribute(typeof(DisplayNameAttribute)) != null
               //         select r).ToArray();                props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                       .Select(x => new 
                       { 
                           Property = x, 
                           Attribute = (ExportAttribute)Attribute.GetCustomAttribute(x, typeof(ExportAttribute), true) 
                       })
                       .Where(x => x.Property.GetCustomAttribute(typeof(DisplayNameAttribute)) != null )
                       .OrderBy(x => x.Attribute != null ? x.Attribute.FieldOrder : -1)
                       .Select(x => x.Property )
                       .ToArray();
           }
           catch (Exception ex)
           {
               AppLogger.LogErrorOnly(ex);
           }
           return props;        }


c# 根据自定义Attribute排序的更多相关文章

  1. XsdGen:通过自定义Attribute与反射自动生成XSD

    前言 系统之间的数据交互往往需要事先定义一些契约,在WCF中我们需要先编写XSD文件,然后通过自动代码生成工具自动生成C#对象.对于刚刚接触契约的人来说,掌握XMLSpy之类的软件之后确实比手写XML ...

  2. 2.C#自定义Attribute

    阅读目录    一:C#自定义Attribute    二:AttributeUsageAttribute中的3个属性(Property)中的AttributeTargets   三:Attribut ...

  3. ORACLE自定义顺序排序-转

    ORACLE可以借助DECODE函数,自定义顺序排序: select * from ( select 'Nick' as item from dual union all select 'Viki' ...

  4. 自定义Attribute 服务端校验 客户端校验

    MVC 自定义Attribute 服务端校验 客户端校验/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) *//* Autho ...

  5. [wordpress]根据自定义字段排序并根据自定义字段查询

    Wordpress中,根据根据自定义字段排序和查询是通过WP_Query()方法 如根据 一个自定义的sort的数字字段从小到大进行排序 $args = array( 'post_type' => ...

  6. C#自定义Attribute值的获取与优化

    C#自定义Attribute值的获取是开发中会经常用到的,一般我们的做法也就是用反射进行获取的,代码也不是很复杂. 1.首先有如下自定义的Attribute [AttributeUsage(Attri ...

  7. .net c#获取自定义Attribute

    前言: 在c#开发中,有时候我们需要读取 Attribute中的信息(关于Attribute , 我自己把他理解成一个可以为类,属性标记的东西,这个标记可以为你提供一些关于类,方法,属性的额外信息) ...

  8. java中的排序(自定义数据排序)--使用Collections的sort方法

    排序:将一组数据按相应的规则 排列 顺序 1.规则:       基本数据类型:日常的大小排序. 引用类型: 内置引用类型(String,Integer..),内部已经指定规则,直接使用即可.---- ...

  9. js将对象数组按照自定义规则排序

    javascript对一个对象数组进行自定义规则排序,对象中有两个字段. 按照对象中一个字段a的值从小到大规则排序, 效果如下: 排序前: [0]:a=9,b=3 [1]:a=33,b=7 [2]:a ...

随机推荐

  1. css渐变色

    <!DOCTYPE html><html><head> <meta http-equiv="content-type" content=& ...

  2. jQuery的live()方法对hover事件的处理示例

    hover([over,]out) 一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法 当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数. 当鼠标移出这个元素时,会触发指定的第二个 ...

  3. VB php JAVA关于数据库连接数过多的解决方法

    这里讲解一个关于数据库连接多多的解决办法 一般都会在方法中进行数据库的开,利用和关 不过如果在一个循环里面使用的时候 这样数据库的连接数就会过多,如果是1万次的话,数据库服务器可能就会当机 PHP 中 ...

  4. [转帖]了解AmbiLight知识

    了解科技前沿的方法..American Online=AOL.algorithm算法.(Denzel say, and I don't know) Engadget瘾科技网站.英文版Engadget网 ...

  5. MySQL 选择数据库

    MySQL 选择数据库 在你连接到 MySQL 数据库后,可能有多个可以操作的数据库,所以你需要选择你要操作的数据库. 从命令提示窗口中选择MySQL数据库 在 mysql> 提示窗口中可以很简 ...

  6. Neutron/ML2学习

    Neutron/ML2 Neutron ML2 模块层2(ml2)插件是一种允许OpenStack网络同时地利用在复杂现实数据中心发现的各种第二层网络技术的框架.目前它与存在的openvswitch. ...

  7. 我是怎样自学日语的(太TM励志了!)

    学日语并不难,难是难在你有没有信心学好日语,有没有恒心学好日语.如果三天打鱼两天晒网的话,我劝你还是趁早死心,在语言世界里没有任何的捷径,有的只是艰辛和不懈的努力. 我自认为自己在学语言方面很有天赋, ...

  8. 03_RHEL7.1去掉注册提示

    # rpm –qa|grep subscription-manager 出现类似下面的代码: subscription-manager-firstboot-1.13.22-1.el7.x86_64 s ...

  9. jquery 的attr()方法解析

    我想用jquery的attr()方法修改一个li小圆点的背景颜色和外边框的时候:刚开始 $("#shanghai-btn").attr({background:"#999 ...

  10. php中的双引号和单引号的区别?

    1.单引号里面的字符串直接全部转义,原样输出(即:单引号内部的变量不会被执行) 2.双引号里面的变量会被替换(即:变量会执行) 例如:$name = 'hello';echo "the $n ...