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. vs2010-error LNK1123: failure during conversion to COFF: file invalid or corrupt

    在项目上右键->Properties-> configuration Properties->Enable Incremental Linking(设置为No). ref: Link ...

  2. iOS开发: 向右滑动手势功能实现

    在navigationController中实现向右滑动 返回功能 系统提供的backbarbuttonitem,不用添加任何代码即可实现向右滑动后退功能,但是往往要对按钮修改样式等时,就需要自定义l ...

  3. apache-maven-3.3.9集成apache-tomcat-7.0.72实现热部署配置细节

    1.开发环境.Maven.Tomcat安装不作描述,搜索引擎很多文章可供参考. 2.Tomcat配置文件修改 1)Tomcat管理权限配置 1.1)在tomcat安装目录下找到tomcat-users ...

  4. Hibernate 一对多双向关联Demo

    以Classes[班级]和Student[学生]为例的Demo //Classes.java public class Classes implements Serializable { privat ...

  5. sqlite3 小结

    sqlite安装 DDL(数据定义语言):create.alter.drop DML(数据操作语言):insert.update.delete DQL(数据查询语言):select sqlite3 命 ...

  6. Qt信号槽连接在有默认形参下的情况思考

    写下这个给自己备忘,比如函数 ) 你在调用端如论是test(3)或者test(),都可以正确调用到这个函数. 但是,如果放到Qt中的信号槽的话,这个还是值得讲一讲的,不然的话,可能会引起相应的误会. ...

  7. jquery选择器专题

    $(“p”).addClass(css中定义的样式类型); 给某个元素添加样式$(“img”).attr({src:”test.jpg”,alt:”test Image”}); 给某个元素添加属性/值 ...

  8. 关于json.ajax ,php的那点事

    $.ajax({ type:'post'/'get'  两者选其一 url:    地址 data: "newdata="+newdata+"&olddata=& ...

  9. Python学习笔记四--字典与集合

    字典是Python中唯一的映射类型.所谓映射即指该数据类型包含哈希值(key)和与之对应的值(value)的序列.字典是可变类型.字典中的数据是无序排列的. 4.1.1字典的创建及赋值 dict1={ ...

  10. bzoj3574[Hnoi2014]抄卡组

    http://www.lydsy.com/JudgeOnline/problem.php?id=3574 我们发现如果所有的字符串都有*,那么只需要比较他们的“前缀”和“后缀”相同即可.“前缀”指第一 ...