惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
爱范儿
爱范儿
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
S
SegmentFault 最新的问题
S
Schneier on Security
V
Vulnerabilities – Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Latest news
Latest news
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
L
LINUX DO - 热门话题
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
SecWiki News
SecWiki News
H
Hacker News: Front Page
aimingoo的专栏
aimingoo的专栏
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Threatpost
罗磊的独立博客
L
LangChain Blog
The Last Watchdog
The Last Watchdog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
K
Kaspersky official blog
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
N
News | PayPal Newsroom
美团技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
T
The Blog of Author Tim Ferriss
N
Netflix TechBlog - Medium
博客园 - 【当耐特】
Cyberwarzone
Cyberwarzone

博客园 - 小寒

Postman or TestNG for automated testing adb.exe 已停止工作 解决 用户中心 - 博客园 移动UI设计 c3p0数据源的使用初步及Mysql8小时问题解决 npm+node+cordova+ionic 版本匹配 ngrok - 小寒 vi command speech recognition resource mysql Workbench 执行删除命令 备份Mysql数据库BAT脚本 C# double 四舍五入 mysql CREATE USER ConvertHelper 通用类 Cordova Ionic AngularJS centos mariadb Nginx 负载均衡 使用Aspose.Cells生成Excel的方法详解(转)
自定义属性
小寒 · 2015-12-29 · via 博客园 - 小寒

属性定义

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public class ColumnNameAttribute : Attribute
    {
        private string _columnName;
        public ColumnNameAttribute(string columnName, string columnChsName=null)
        {
            this._columnName = columnName;
            this._columnChsName = columnChsName;
        }

        public string ColumnName
        {
            get { return _columnName; }
        }

        private string _columnChsName;

        public string ColumnChsName
        {
            get { return _columnChsName; }
        }
    }

  属性使用

var properties = typeof(T).GetProperties().Where(v => v.IsDefined(typeof(ColumnNameAttribute), true)).ToList();

 foreach (var pro in properties)
            {
                var sourctValue = GetString(pro.GetValue(sourceObj, null));
                var newValue = GetString(pro.GetValue(newObj, null));
                if (sourctValue != newValue)
                {
                    string colName = ((ColumnNameAttribute)pro.GetCustomAttributes(typeof(ColumnNameAttribute), true)[0]).ColumnChsName;
                    logContent.AppendLine("</br>" + colName + ":从" + sourctValue + " 变更到 " + newValue);
                    hasChanged = true;
                }
            }

  私有方法

        private static string GetString(object o)
        {
            if (o == null || o== DBNull.Value)
            {
                return string.Empty;
            }
            else
            {
                return o.ToString();
            }
        }