Skip to content

Commit 730bf9b

Browse files
committed
Merge branch 'Marusyk-rmarusyk/ScriptCallerInfo-Alias' into develop
* Marusyk-rmarusyk/ScriptCallerInfo-Alias: Add ScriptCallerAliases
2 parents cd26e63 + 71e4a92 commit 730bf9b

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
using Cake.Core;
4+
using Cake.Core.Annotations;
5+
6+
namespace Cake.Common.Diagnostics
7+
{
8+
/// <summary>
9+
/// Contains functionality related to diagnostics.
10+
/// </summary>
11+
[CakeAliasCategory("Diagnostics")]
12+
public static class ScriptCallerAliases
13+
{
14+
/// <summary>
15+
/// Performs script caller information.
16+
/// </summary>
17+
/// <param name="context">The context.</param>
18+
/// <param name="memberName">The member name.</param>
19+
/// <param name="sourceFilePath">The source file path.</param>
20+
/// <param name="sourceLineNumber">The source line number.</param>
21+
/// <returns>A <see cref="GetCallerInfo"/> instance representing the caller information.</returns>
22+
[CakeMethodAlias]
23+
public static ScriptCallerInfo GetCallerInfo(
24+
this ICakeContext context,
25+
[CallerMemberName] string memberName = "",
26+
[CallerFilePath] string sourceFilePath = "",
27+
[CallerLineNumber] int sourceLineNumber = 0)
28+
{
29+
if (context == null)
30+
{
31+
throw new ArgumentNullException(nameof(context));
32+
}
33+
34+
return new ScriptCallerInfo(memberName, sourceFilePath, sourceLineNumber);
35+
}
36+
}
37+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Cake.Core.IO;
2+
3+
namespace Cake.Common.Diagnostics
4+
{
5+
/// <summary>
6+
/// Represents a caller information.
7+
/// </summary>
8+
public sealed class ScriptCallerInfo
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="ScriptCallerInfo"/> class.
12+
/// </summary>
13+
/// <param name="memberName">The member name.</param>
14+
/// <param name="sourceFilePath">The source file path.</param>
15+
/// <param name="sourceLineNumber">The source line number.</param>
16+
public ScriptCallerInfo(string memberName, FilePath sourceFilePath, int sourceLineNumber)
17+
{
18+
MemberName = memberName;
19+
SourceFilePath = sourceFilePath;
20+
SourceLineNumber = sourceLineNumber;
21+
}
22+
23+
/// <summary>
24+
/// Gets the method or property name of the caller to the method.
25+
/// </summary>
26+
public string MemberName { get; }
27+
28+
/// <summary>
29+
/// Gets the full path of the source file that contains the caller.
30+
/// </summary>
31+
public FilePath SourceFilePath { get; }
32+
33+
/// <summary>
34+
/// Gets the line number in the source file at which the method is called.
35+
/// </summary>
36+
public int SourceLineNumber { get; }
37+
38+
/// <summary>
39+
/// Returns a <see cref="System.String" /> containing the full path of the source file and the line number in the source file at which the method is called.
40+
/// </summary>
41+
/// <returns>
42+
/// A <see cref="System.String" /> containing the full path of the source file and the line number in the source file at which the method is called.
43+
/// </returns>
44+
public override string ToString() => $"{SourceFilePath}:{SourceLineNumber}";
45+
}
46+
}

0 commit comments

Comments
 (0)