Last active
December 26, 2015 01:19
-
-
Save hagbarddenstore/7070186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace A | |
| { | |
| using System; | |
| using System.Linq; | |
| using System.ComponentModel; | |
| public static class Program | |
| { | |
| public static void Main() | |
| { | |
| var ceo = new CEO(); | |
| var worker = new Worker(); | |
| Console.WriteLine("{0}", ceo.GetDisplayName()); | |
| Console.WriteLine("{0}", worker.GetDisplayName()); | |
| } | |
| private static string GetDisplayName<T>(this T self) | |
| { | |
| var attribute = typeof(T).GetCustomAttributes(typeof(DisplayNameAttribute), false) | |
| .OfType<DisplayNameAttribute>() | |
| .FirstOrDefault(); | |
| return attribute != null ? attribute.DisplayName : "N/A"; | |
| } | |
| } | |
| public abstract class Employee | |
| { | |
| } | |
| [DisplayName("Worker")] | |
| public class Worker : Employee | |
| { | |
| } | |
| public class CEO : Employee | |
| { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment