# Runtime\_CompilerServices\_CallerFileAttribute

***

**1. Logging the Source File Name:**

```csharp
[Runtime_CompilerServices.CallerFile]
public static string GetCallerFileName() => default!;
```

**2. Logging the Source File Path:**

```csharp
[Runtime_CompilerServices.CallerFilePath]
public static string GetCallerFilePath() => default!;
```

**3. Generating a Source File Line Number:**

```csharp
[Runtime_CompilerServices.CallerLineNumber]
public static int GetCallerLineNumber() => default!;
```

**4. Generating a Source File Member Name:**

```csharp
[Runtime_CompilerServices.CallerMemberName]
public static string GetCallerMemberName() => default!;
```

**5. Debugging with Source File Information:**

```csharp
public static void DebugWithSourceInfo(
    [Runtime_CompilerServices.CallerFilePath] string filePath,
    [Runtime_CompilerServices.CallerLineNumber] int lineNumber,
    [Runtime_CompilerServices.CallerMemberName] string memberName)
{
    // Log or handle the source file information.
}
```

**6. Exception Handling with Source File Information:**

```csharp
try
{
    // Code that may throw an exception.
}
catch (Exception ex)
{
    Console.WriteLine(
        $"Exception occurred in file {ex.CallerFilePath}, line {ex.CallerLineNumber}, member {ex.CallerMemberName}.");
}
```

**7. Dependency Injection with Source File Information:**

```csharp
public interface ILog
{
    void Log(string message, [Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber);
}

public class Logger : ILog
{
    public void Log(string message, string filePath, int lineNumber)
    {
        // Log the message with source file information.
    }
}
```

**8. Unit Testing with Source File Information:**

```csharp
[Test]
public void TestMethod([Runtime_CompilerServices.CallerMemberName] string memberName)
{
    // Assert or verify method behavior with source file information.
}
```

**9. Performance Profiling with Source File Information:**

```csharp
public static void ProfileMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Measure the performance of the method and log it with source file information.
}
```

**10. Code Generation with Source File Information:**

```csharp
public static void GenerateCode([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Generate code based on the source file information.
}
```

**11. Custom Debugging Attributes:**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class DebugAttribute : Attribute
{
    [Runtime_CompilerServices.CallerFilePath]
    public string FilePath { get; set; }

    [Runtime_CompilerServices.CallerLineNumber]
    public int LineNumber { get; set; }
}

[Debug]
public void DebugMethod()
{
    // Trigger the DebugAttribute to log source file information.
}
```

**12. Error Handling with Source File Information:**

```csharp
public static void HandleError([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber, Exception ex)
{
    // Log or report the error with source file information.
}
```

**13. Exception Filters with Source File Information:**

```csharp
try
{
    // Code that may throw an exception.
}
catch (Exception ex) when (ex.CallerFilePath.Contains("MyClass.cs"))
{
    // Handle the exception if it occurred in a specific file.
}
```

**14. Logging with Source File Information:**

```csharp
public static void LogMessage([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber, string message)
{
    // Log the message with source file information.
}
```

**15. Tracing with Source File Information:**

```csharp
public static void TraceMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trace the entry or exit of a method with source file information.
}
```

**16. Unit Testing with Source File Information:**

```csharp
[Test]
public void TestMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Assert or verify method behavior with source file information.
}
```

**17. Code Metrics with Source File Information:**

```csharp
public static void MeasureCodeSize([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Measure the size of a code block with source file information.
}
```

**18. Performance Profiling with Source File Information:**

```csharp
public static void ProfileMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Profile the performance of a method with source file information.
}
```

**19. Code Coverage with Source File Information:**

```csharp
public static void TrackCodeCoverage([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Track the code coverage of a method with source file information.
}
```

**20. Code Generation with Source File Information:**

```csharp
public static void GenerateCode([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Generate code based on the source file information.
}
```

**21. Custom Attributes with Source File Information:**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class SourceInfoAttribute : Attribute
{
    [Runtime_CompilerServices.CallerFilePath]
    public string FilePath { get; set; }

    [Runtime_CompilerServices.CallerLineNumber]
    public int LineNumber { get; set; }
}

[SourceInfo]
public void MethodWithSourceInfo()
{
    // Trigger the SourceInfoAttribute to log source file information.
}
```

**22. Debugging with Source File Information:**

```csharp
public static void DebugMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger debugging with source file information.
}
```

**23. Logging with Source File Information:**

```csharp
public static void LogMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger logging with source file information.
}
```

**24. Performance Profiling with Source File Information:**

```csharp
public static void ProfileMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger performance profiling with source file information.
}
```

**25. Code Coverage with Source File Information:**

```csharp
public static void TrackCodeCoverage([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger code coverage tracking with source file information.
}
```

**26. Exception Handling with Source File Information:**

```csharp
try
{
    // Code that may throw an exception.
}
catch (Exception ex)
{
    [Runtime_CompilerServices.CallerFilePath]
    string filePath = default!;

    [Runtime_CompilerServices.CallerLineNumber]
    int lineNumber = default!;

    // Handle the exception with source file information.
}
```

**27. Unit Testing with Source File Information:**

```csharp
[Test]
public void TestMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger unit testing with source file information.
}
```

**28. Code Generation with Source File Information:**

```csharp
public static void GenerateCode([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger code generation with source file information.
}
```

**29. Custom Attributes with Source File Information:**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class SourceFileInfoAttribute : Attribute
{
    [Runtime_CompilerServices.CallerFilePath]
    public string FilePath { get; set; }

    [Runtime_CompilerServices.CallerLineNumber]
    public int LineNumber { get; set; }
}

[SourceFileInfo]
public void MethodWithSourceFileInfo()
{
    // Trigger the SourceFileInfoAttribute to log source file information.
}
```

**30. Logging with Source File Information:**

```csharp
public static void LogMessage([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber, string message)
{
    // Trigger logging with source file information.
}
```

**31. Tracing with Source File Information:**

```csharp
public static void TraceMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger tracing with source file information.
}
```

**32. Unit Testing with Source File Information:**

```csharp
[Test]
public void TestMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger unit testing with source file information.
}
```

**33. Code Metrics with Source File Information:**

```csharp
public static void MeasureCodeSize([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger code metrics calculation with source file information.
}
```

**34. Performance Profiling with Source File Information:**

```csharp
public static void ProfileMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger performance profiling with source file information.
}
```

**35. Code Coverage with Source File Information:**

```csharp
public static void TrackCodeCoverage([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger code coverage tracking with source file information.
}
```

**36. Code Generation with Source File Information:**

```csharp
public static void GenerateCode([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger code generation with source file information.
}
```

**37. Custom Attributes with Source File Information:**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class SourceCodeAttribute : Attribute
{
    [Runtime_CompilerServices.CallerFilePath]
    public string FilePath { get; set; }

    [Runtime_CompilerServices.CallerLineNumber]
    public int LineNumber { get; set; }
}

[SourceCode]
public void MethodWithSourceCode()
{
    // Trigger the SourceCodeAttribute to log source file information.
}
```

**38. Logging with Source File Information:**

```csharp
public static void LogMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger logging with source file information.
}
```

**39. Tracing with Source File Information:**

```csharp
public static void TraceMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger tracing with source file information.
}
```

**40. Unit Testing with Source File Information:**

```csharp
[Test]
public void TestMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger unit testing with source file information.
}
```

**41. Code Metrics with Source File Information:**

```csharp
public static void MeasureCodeSize([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger code metrics calculation with source file information.
}
```

**42. Performance Profiling with Source File Information:**

```csharp
public static void ProfileMethod([Runtime_CompilerServices.CallerFilePath] string filePath, [Runtime_CompilerServices.CallerLineNumber] int lineNumber)
{
    // Trigger performance profiling with source file information.

```
