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

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - ☆用心生活☆

BI-日期维度表-SQL SERVER SQL SERVER 2014 缺少Business Intelligence 解决办法 有未提交的事务。是否要在关闭窗口之前提交这些事务? MSSQL之2005版本之后的行号分区妙用:row_number() over(PARTITION BY X1,X2.. ORDER BY X1,X2... ) IIS发布服务时候无法浏览,提示需要MIME注册 深浅COPY之我所理解,望拍砖交流。 windows developer preview 安装体验。 MSSQL之自增列丢失ID找回--粗略解决方案 datagirdview进行数据统计 水晶报表之分页预留空白方便打印信纸 DataGridView数据呈现之行信息--HitTestInfo--用于选择呈现第一行 SQLMETAL使用LINQ自动代码生成工具命令残参数详解 aspnet_compiler.exe 命令参数详解 妙用MSSQL的REVERSE()反转函数显示文件路径的文件名称 2011年上半年总结 windows phone 7 学习初旅1 MSSQL自定义函数之数据格式化为千分位格式 MSSQL获取指定表的列名信息,描述,数据类型,长度 The product level is insufficient for component "Data Conversion 1"
获取对象属性和值 日志记录
☆用心生活☆ · 2013-01-07 · via 博客园 - ☆用心生活☆

对于经常对数据操作的开发者来说,一条记录(MODEL)的数据更改提交,删除等操作,会记录每条记录的详细信息,写入日志表,因此可以采用下面这代码生成一个字符串进行日志记录。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// 日志工具类
    /// </summary>
    public class LogHelper
    {
        /// <summary>
        /// 获取每个对象包含的属性及值的一条字符串,默认以逗号分割
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="item">目标类型对象(实例)</param>
        /// <returns></returns>
        public static string GetInstancePropertyNameValue<T>(T item)
        {
            Type t = typeof(T);
            StringBuilder sb = new StringBuilder();
             System.Reflection.PropertyInfo[] properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            foreach (var i in properties)
            {
                string name = i.Name;
                object value = i.GetValue(item, null);

                if (i.PropertyType.IsValueType || i.PropertyType.Name.StartsWith("String"))
                {
                    sb.Append(string.Format("{0}:{1},", name, value is Nullable ? string.Empty : value));
                }

            }
            return sb.ToString();
        }
    }