调用者信息特性
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
{ }
}
原文:https://www.cnblogs.com/wjcx-sqh/p/10685533.html