首页 > Windows开发 > 详细

C# 5.0-.Net新特性

时间:2019-04-10 20:19:47      阅读:140      评论:0      收藏:0      [点我收藏+]

调用者信息特性

CallerMemberNameAttribute | CallerFilePathAttribute | CallerLineNumberAttribute

.NET Framework 4.5 中新增,用于请求编译器在编译过程中进行代码的转换 。

使用方式:直接调用即可

public static void TraceMessage(string message, string errCode, 
                [CallerMemberNameAttribute] string memberName = "",
                [CallerFilePathAttribute] string filePath = "",
                [CallerLineNumberAttribute] int lineNumber = 0)

若要在 .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
    { }
}

 

C# 5.0-.Net新特性

原文:https://www.cnblogs.com/wjcx-sqh/p/10685533.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!