标题中所说的三个特性 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. Linux命令——lspci

    参考:7 Linux lspci Command Examples to Get PCI Bus Hardware Device Info 简介 lspci可以看成“ls” + “pci”.lspci ...

  2. Elasticsearch 术语介绍和CRUD实际操作入门

    一.Elastic Stack 核心Elasticsearch Elasticsearch 是一个分布式.RESTful 风格的搜索和数据分析引擎.Elasticsearch 是面向文档的,这就意味着 ...

  3. commons-io之FileUtils、IOUtils

    原文:https://blog.csdn.net/justry_deng/article/details/93616705 commons-io简单说明:Common IO 是一个工具库,用来帮助开发 ...

  4. Spring -12 -声明式事务及完整的XML配置文件信息 -声明式事务中的相关属性(tx:advice的标签)

    1.编程式事务: 1.1由程序员编程事务控制代码. 1.2OpenSessionInView 就属于编程式事务: session.commit()和rollback() 2.声明式事务: 2.1事务控 ...

  5. 深度学习算法 之DCGAN(写得不系统,后期再总结,大家可简单阅览一下)

    目录 1.基本介绍 2.模型 3.优缺点/其他 参考 1.基本介绍 DCGAN是生成对抗网络GAN中一种常见的模型结构.其中的生成器和判别器都是神经网络模型. GAN是一种生成式对抗网络,即通过对抗的 ...

  6. gradle 构建scala程序

    一.build.gradle 二.gradle build ===================== 执行scala scala main.scala

  7. css Grid布局

    CSS Grid 布局完全指南(图解 Grid 详细教程)https://www.html.cn/archives/8510#prop-grid-gap 5分钟学会 CSS Grid 布局https: ...

  8. 十三.Java使用Protobuf3

    为什么使用Protobuf? 本教程翻译自谷歌开发者官网,原文地址:https://developers.google.com/protocol-buffers/docs/javatutorial.开 ...

  9. vue3 RFC初尝试

    由于vue3.x还没有正式发布,所以可以通过安装包vue-function-api提前尝试 npm install vue-function-api --save main.js import Vue ...

  10. set_index

    Signature: df.set_index( ['keys', 'drop=True', 'append=False', 'inplace=False', 'verify_integrity=Fa ...