Skip to content

Instantly share code, notes, and snippets.

@jindeveloper
Created August 21, 2020 07:34
Show Gist options
  • Select an option

  • Save jindeveloper/8a53c15c32a4f9ed219ab01dd8b6f41d to your computer and use it in GitHub Desktop.

Select an option

Save jindeveloper/8a53c15c32a4f9ed219ab01dd8b6f41d to your computer and use it in GitHub Desktop.
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