HAVIT Knowledge Base

Vývoj webových aplikací, .NET, SQL, návrh
Welcome to HAVIT Knowledge Base Sign in | Join | Help
-
Home Články Forums Obrázky Soubory

.NET Framework

Microsoft .NET Framework, Base Class Library

C# 5: Caller Info Attributes

Zajímavá novinka v C# 5 poslouží například k logování. Následující příklad funguje ve Visual Studio 11 Beta:

    class Program
    {
        static void Main(string[] args)
        {
            Log("Message");
        }

        static void Log(string message,
            [CallerMemberName] string callerMemberName = "",
            [CallerFilePath] string callerFilePath = "",
            [CallerLineNumber] int callerLineNumber = 0)
        {
            Console.WriteLine(message);
            Console.WriteLine(callerMemberName);
            Console.WriteLine(callerFilePath);
            Console.WriteLine(callerLineNumber);
        }
    }
Výstupem je např:

Message
Main
d:\Development\CallerAttributes\CallerAttributes\Program.cs
14

Published 29. února 2012 20:34 by Robert Haken

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

What do you think?

(required) 
(optional)
(required) 
Enter the code you see below

Submit