> ## Content Index
> Fetch the complete content index at: https://informatic-ar.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Caller Info Attributes in C# 5.0
- URL: https://informatic-ar.com/caller-info-attributes-in-c-5-0/
- Published: 2013-10-02T07:49:02.000Z
- Updated: 2026-10-03T22:32:04.000Z
- Author: Ahmed Elsayed
- Tags: دوت نت, c++, C# 5.0, .NET, .NET 4.5, #wordpress-archive, #Import 2026-10-03 20:48

في بعض الاحيان عندما تكتب كود تحتاج لمعرفة معلومات عن ال Method التي منها تم استدعاء كودك !  
قبل C# 5 كنا نستخدم الكلاس System.Diagnostics.StackFrame , علي سبيل المثال

```csharp
using System;
using System.Diagnostics;
namespace CS_05
{
class Program
{
    static void Main(string[] args)
    {
        Print("Hello World");
        Console.ReadKey();
    }
    static void Print(string message)
    {
        var sf = new StackFrame(1, true); // Back up 1 level from the current method
        var methodName = sf.GetMethod().Name;
        var sourceFile = sf.GetFileName();
        var lineNumber = sf.GetFileLineNumber();
        Console.WriteLine("[{2} -- {0}] - {1} ({3}:{4})", methodName, message, DateTime.Now,
                          sourceFile, lineNumber);
    }
}
}
```

النائج سيكون ع هذا النحو :

```csharp
[2 / 22 / 2013 11:11:15 PM-- Main]
- Hello World(f:\VisualStudioProjects\CS_05\CS_ 05\Program.cs: 9)
```

في الاصدار الجديد للغة C# تم توفير Attributes جديدة لل Methods ويمكن استخدامها كالتالي :

```csharp
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace CS_05
{
class Program
{
    static void Main(string[] args)
    {
        Print("Hello World");
        Console.ReadKey();
    }
    private static void Print(string message, [CallerMemberName] string methodName = null,
                              [CallerFilePath] string sourceFile = null,
                              [CallerLineNumber] int lineNumber = 0)
    {
        Console.WriteLine("[{2} -- {0}] - {1} ({3}:{4})", methodName, message, DateTime.Now,
                          sourceFile, lineNumber);
    }
}
}
```

والناتج واحد :)

هذه الطرق كلها مفيدة في حالة اذا كنت تريد ان تعرف من اي Method يتم استدعاء Method اخري؛ وبالتالي ستسهل عليك اقتناص الاخطاء في برنامجك واصلاحها.