Giter VIP home page Giter VIP logo

nmsreflector's Introduction

NMSReflector

##简介: 在我们遍历reader,excel表格,文件解析等其他需求时,难免要根据列名去给model赋值,为了简化操作,写了这个类库。考虑到性能,采用反射发出技术;考虑到易用性,本库对object类型做了扩展,以方便程序员使用。

##案例1:

    public class Student : INMSReflector
    {
        public string Name;
        public string Description { get; set; }

        public static string StaticField;
        public static string StaticProperty { get; set; }
    }

###引用步骤:

  Step1 :  引用类库.
  Step2 :  using NMSReflector.
  Step3 :  将你的类实现INMSReflector接口;(当然了,如果你嫌麻烦,可以改一下源码,在ModelOperator.cs中).
  Step4 :  用Create方法创建缓存. (会扫描搜索入口程序集的所有类)

###用法:

   ModelOperator.Create();
   Student t = new Student();

   //普通字段
   t.Name = "小明";
   t.EmitSet("Name", "小明胸前的红领巾更加鲜艳了!");
   Console.WriteLine(t.Name);
   Console.WriteLine(t.EmitGet("Name"));

   //普通属性
   t.EmitSet("Description", "他爱着小刚");
   Console.WriteLine(t.Description);
   Console.WriteLine(t.EmitGet("Description"));

   //静态字段
   t.EmitSet("StaticFiled", "是他挨着小刚");
   Console.WriteLine(Student.StaticField);
   Console.WriteLine(t.EmitGet("StaticField"));

   //静态属性
   t.EmitSet("StaticProperty", "刚才打错了");
   Console.WriteLine(Student.StaticProperty);
   Console.WriteLine(t.EmitGet("StaticProperty"));
  

###结果:

##案例2:

    public class Student : INMSReflector
    {
        public string Name;
        [Column("Note")]
        public string Description { get; set; }

        public static string StaticField;

        public static string StaticProperty { get; set; }
    }

###注意:

  这里的标签是来自于System.ComponentModel.DataAnnotations.Schema;
  所以需要using System.ComponentModel.DataAnnotations.Schema;

###用法:

    ModelOperator.Create();
    Student t = new Student();

    t.EmitSet("Note", "设置标签");
    Console.WriteLine(t.Description);
    Console.WriteLine(t.EmitGet("Note"));

###结果:

##其他:

    //获取真实属性名
    ModelOperator.GetRealName<Student>("Note");
    //获取映射名
    ModelOperator.GetAttributeName<Student>("Description");
    //其他更多方法详见ModelOperator.cs 注释已经写好

##性能测试:

##优点:

   就是看着放心,用着舒心....

Copyright 2016 Xin Hu ([email protected])

nmsreflector's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.