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; | |
| namespace CSharp_Attributes_Walkthrough.My_Custom_Attributes | |
| { | |
| /// <summary> | |
| /// This class is a custom attribute class. | |
| /// Moreover, it is using the AttributeUsage attribute to annotate | |
| /// that this attribute is applicable only to class, struct and property. | |
| /// </summary> | |
| [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property)] |
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; | |
| namespace CSharp_Attributes_Walkthrough.My_Custom_Attributes | |
| { | |
| public class AliasAttribute : Attribute | |
| { | |
| //This is how to define a custom attributes. | |
| } | |
| } |
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; | |
| namespace CSharp_Attributes_Walkthrough.My_Custom_Attributes | |
| { | |
| public class AliasAttribute : Attribute | |
| { | |
| /// <summary> | |
| /// These parameters will become mandatory once have you decided to use this attribute. | |
| /// </summary> | |
| /// <param name="alias"></param> |
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 CSharp_Attributes_Walkthrough.My_Custom_Attributes; | |
| using System; | |
| namespace CSharp_Attributes_Walkthrough.My_Custom_Attributes | |
| { | |
| public class AliasAttribute : Attribute | |
| { | |
| //.... | |
| //Added an optional-parameter |
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
| [Fact] | |
| public void Test_GetAll_AttributeTargets() | |
| { | |
| var targets = Enum.GetNames(typeof(AttributeTargets)); | |
| foreach (var target in targets) | |
| { | |
| this._output.WriteLine($"AttributeTargets.{target}"); | |
| } | |
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 CSharp_Attributes_Walkthrough.My_Custom_Attributes; | |
| using System; | |
| namespace Implementing_Csharp_Attributes_101 | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var customer = new Customer { Firstname = "Jin Vincent" , LastName = "Necesario" }; |
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; } |
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
| /*forEach loop*/ | |
| let amounts = [1.25, 2.25, 3.25, 4.25]; | |
| /** | |
| * Outputs: | |
| * 1.25 | |
| * 2.25 | |
| * 3.25 | |
| * 4.25 | |
| */ |
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
| const TOTAL_WORKING_DAYS = 261; | |
| const getDailyRate = salary => Math.floor(((salary * 12) / (TOTAL_WORKING_DAYS))); | |
| const dailyRate = employee => Object.assign({}, { employee: employee.employee, dailyRate: getDailyRate(employee.salary) }); | |
| //Returns a new set of empoloyees with dailyRate and name | |
| const newEmployees = employees.map(dailyRate); | |
| //new data |
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
| const TOTAL_WORKING_DAYS = 261; | |
| //Horrible in my opinion, worst someone will say it is ugly. | |
| const dailyRate = (item, index, array) => array[index].dailyRate = Math.floor(((item.salary * 12) / (TOTAL_WORKING_DAYS))); | |
| //undefined as forEach doesn't return any results. | |
| let dailyRateEmployeeResults = employees.forEach(dailyRate); | |
| console.log(dailyRateEmployeeResults);//undefined |