به دست آوردن اطلاعات کد اجراکننده یک متد
نویسنده: سیدمجتبی حسینی
تاریخ: ۱۳۹۱/۰۷/۱۸ ۰:۷
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
using System;
using System.Runtime.CompilerServices;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
Test();
Console.Read();
}
static void Test(
[CallerMemberName] string memberName = null,
[CallerFilePath] string filePath = null,
[CallerLineNumber] int lineNumber = 0)
{
Console.WriteLine(memberName);
Console.WriteLine(filePath);
Console.WriteLine(lineNumber);
}
}
}
Main c:\Pojects\ConsoleApplication8\Program.cs 9
public static void LogExpression<T>(
T value,
[CallerArgumentExpression("value")] string expression = null)
{
Console.WriteLine($"{expression}: {value}");
} var person = new Person("Vahid", "N.");
LogExpression(person.FirstName); person.FirstName: Vahid
LogExpression(person.FirstName, "person.FirstName");
public static void EnsureArgumentIsNotNull<T>(
T value,
[CallerArgumentExpression("value")] string expression = null)
{
if (value is null)
throw new ArgumentNullException(expression);
}
public static void Foo(string name)
{
EnsureArgumentIsNotNull(name); // if name is null, throws ArgumentNullException: "Value cannot be null. (Parameter 'name')"
...
} if (name is null)
{
throw new ArgumentNullException(nameof(name));
} ArgumentNullException.ThrowIfNull(name);
public static void ThrowIfNull(
[NotNull] object? argument,
[CallerArgumentExpression("argument")] string? paramName = null)