Created
August 21, 2020 07:34
-
-
Save jindeveloper/8a53c15c32a4f9ed219ab01dd8b6f41d 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
| using System; | |
| using System.Linq; | |
| namespace CSharp_Attributes_Walkthrough.My_Custom_Attributes | |
| { | |
| [Alias("Filipino_Customers", ConsoleColor.Yellow)] | |
| public class Customer | |
| { | |
| [Alias("Fname", ConsoleColor.White, AlternativeName = "Customer_FirstName")] | |
| public string Firstname { get; set; } | |
| [Alias("Lname", ConsoleColor.White, AlternativeName = "Customer_LastName")] | |
| public string LastName { get; set; } | |
| public override string ToString() | |
| { | |
| //get the current running instance. | |
| Type instanceType = this.GetType(); | |
| //get the namespace of the running instance. | |
| string current_namespace = (instanceType.Namespace) ?? ""; | |
| //get the alias. | |
| string alias = (this.GetType().GetCustomAttributes(false).FirstOrDefault() as AliasAttribute)?.Alias; | |
| return $"{current_namespace}.{alias}"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment