标题中所说的三个特性 CallerMemberNameAttribute / CallerFilePathAttribute / CallerLineNumberAttribute 我们统称为调用者信息特性,正常情况下在 .NET Framework 4.0 中是无法使用的。

  static void Main( string[] args )
{
var productInfo = new ProductInfo(); productInfo.Name = "lumia"; productInfo.PropertyChanged(); Console.ReadKey( true );
}
} public class ProductInfo
{
private string _name; public string Name
{
get { return this._name; }
set
{
this._name = value;
this.PropertyChanged();
}
} public void PropertyChanged([CallerMemberName]string name = "", [CallerLineNumber]int line = , [CallerFilePath]string file = "")
{
Console.WriteLine("------------------------------------------------");
Console.WriteLine($"Name : {name}, \nLine : {line}, \nPath : {file}");
}
}

在 .NET Framework 4.0 中使用需要自己定义这三个特性

namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public class CallerMemberNameAttribute : Attribute
{ } [AttributeUsage(AttributeTargets.Parameter, Inherited = false )]
public class CallerFilePathAttribute : Attribute
{ } [AttributeUsage(AttributeTargets.Parameter, Inherited = false )]
public class CallerLineNumberAttribute : Attribute
{ }
}

NET 4.5 中新增的特性调用者信息特性CallerMemberNameAttribute/CallerFilePathAttribute/CallerLineNumberAttribute的更多相关文章

  1. 在 .NET 4.0 中使用 .NET 4.5 中新增的特性(CallerMemberNameAttribute/CallerFilePathAttribute/CallerLineNumberAttribute)

    介绍 标题中所说的三个特性 CallerMemberNameAttribute / CallerFilePathAttribute / CallerLineNumberAttribute 我们统称为调 ...

  2. 16.2 【C# 5】调用者信息特性

    16.2.1 基本行为 .NET 4.5引入了三个新特性(attribute),即 CallerFilePathAttribute . CallerLineNumber- Attribute 和 Ca ...

  3. C# 调用者信息特性(Attribute)

    .NET 4.5中引用了三种特性(Attribute), 该特性允许获取调用者的当前编译器的执行文件名.所在行数与方法或属性名称. 命名空间 System.Runtime.CompilerServic ...

  4. Performance Tuning guide 翻译 || Performance Tuning Guide 11G中新增特性

    CSDN 对格式支持比較弱.能够到http://user.qzone.qq.com/88285879/blog/1399382878 看一致的内容. Performance Tuning Guide  ...

  5. MySQL5.6中新增特性、不推荐使用的功能以及废弃的功能

    虽然已经使用MySQL5.6版本有一段时间了,但由于没有和之前的版本作过详细比较,所以对于哪些重要的或者不太重要的特性是在新版本中引入的,还有哪些特性已经或者将要从旧版本中移除的并没有一个十分全面的了 ...

  6. GoldenGate12.3中新增的Parallel Replicat (PR)介绍

    Parallel Replicat介绍 在OGG 12.3.0.1中新增的一项特性parallel replicat(并行投递),相对于传统的投递和集成投递(integrated replicat), ...

  7. Vue.js源码中大量采用的ES6新特性介绍:模块、let、const

    1 关于ES6      ECMAScript6(以下简称ES6)是JavaScript语言的最新一代标准,发布于2015年6月,因为ECMA委员会决定从ES6起每年更新一次标准,因此ES6被改名为E ...

  8. ES6中新增let命令使用方法

     在ES6中新增了let命令,该命令的用法与var 类似,但是所声明的变量只能在let命令所在的代码块(最接近let 命令的大括号内)中有效果.但是let 又有一些不同于var 的特性. 1.let定 ...

  9. 带你学习ES5中新增的方法

    1. ES5中新增了一些方法,可以很方便的操作数组或者字符串,这些方法主要包括以下几个方面 数组方法 字符串方法 对象方法 2. 数组方法 迭代遍历方法:forEach().map().filter( ...

随机推荐

  1. zabbix Server 4.0 报警(Action)篇

    zabbix Server 4.0 报警(Action)篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看zabbix默认的Actions 1>.点击默认的Actio ...

  2. Docker容器化技术(上)

    目录 Docker容器化技术 一.介绍 二.Docker的发展 三.Docker安装 四.阿里云Docker镜像加速 五.Docker的基本概念 六.命令 七.Docker宿主机与容器通信 八.容器内 ...

  3. 史诗级干货-python爬虫之增加CSDN访问量

    史诗级干货-python爬虫之增加CSDN访问量 搜索微信公众号:'AI-ming3526'或者'计算机视觉这件小事' 获取更多算法.机器学习干货 csdn:https://blog.csdn.net ...

  4. Python爬取微信公众号素材库

    这是我的之前写的代码,今天发布到博客园上,说不定以后需要用. 开始: #coding:utf-8 import werobot import pymongo   class Gongzhonghao( ...

  5. jdk、jre、jvm三者联系

    JDK(Java Development Kit)是针对Java开发员的产品,是整个Java的核心,包括了Java运行环境JRE.Java工具和Java基础类库.Java Runtime Enviro ...

  6. Error Permission denied when running brew cleanup

    Error Permission denied when running brew cleanup When I try to run `brew cleanup` I get: Warning: S ...

  7. 鼠标经过盒子出现边框(伪元素,定位,css3盒子模型)

    <body> <div> <img src="mi6.png" > </div> </body> div{ width: ...

  8. input file标签限制上传文件类型

    用 input 的file类型标签上传文件,有时需要限制上传文件类型,添加accept属性可以实现 <input type="file" accept="image ...

  9. 连接到 redis 服务

    连接到 redis 服务 <?php //连接本地的 Redis 服务 $redis = new Redis(); $redis->connect('127.0.0.1', 6379); ...

  10. Linux 文件基本属性: chown修改所属组 和 chmod修改文件属性命令

    [root@www /]# ls -l total 64 dr-xr-xr-x 2 root root 4096 Dec 14 2012 bin -rwxrwxr-x 4 root root 4096 ...