-
-
Notifications
You must be signed in to change notification settings - Fork 910
/
CallerInfo.cs
59 lines (53 loc) · 2.31 KB
/
CallerInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System.Runtime.CompilerServices;
using Stride.Core.Annotations;
namespace Stride.Core.Diagnostics
{
/// <summary>
/// A class to store <a href="http://msdn.microsoft.com/en-us/library/hh534540%28v=vs.110%29.aspx">Caller Information</a> attributes.
/// </summary>
public sealed class CallerInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="CallerInfo" /> class.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <param name="memberName">Name of the member.</param>
/// <param name="lineNumber">The line number.</param>
private CallerInfo(string filePath, string memberName, int lineNumber)
{
FilePath = filePath;
MemberName = memberName;
LineNumber = lineNumber;
}
/// <summary>
/// Full path of the source file that contains the caller. This is the file path at compile time.
/// </summary>
public readonly string FilePath;
/// <summary>
/// Method or property name of the caller. See Member Names later in this topic.
/// </summary>
public readonly string MemberName;
/// <summary>
/// Line number in the source file at which the method is called.
/// </summary>
public readonly int LineNumber;
/// <summary>
/// Gets the caller information.
/// </summary>
/// <param name="sourceFilePath">The source file path.</param>
/// <param name="memberName">Name of the member.</param>
/// <param name="sourceLineNumber">The source line number.</param>
/// <returns>A caller information.</returns>
[NotNull]
public static CallerInfo Get([CallerFilePath] string sourceFilePath = "", [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0)
{
return new CallerInfo(sourceFilePath, memberName, sourceLineNumber);
}
public override string ToString()
{
return $"{FilePath}:{MemberName}:{LineNumber}";
}
}
}