using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using System.Reflection; namespace Weee.Models.ExtensionMethods { public static class Extension { // to use this function , pease make sure all the enum value have a display attribute public static string DisplayString(this Enum enumValue) { var enumType = enumValue.GetType(); var Resource = enumType.GetMember(enumValue.ToString()) .First() .GetCustomAttribute() .ResourceType; var name = enumType.GetMember(enumValue.ToString()) .First() .GetCustomAttribute() .Name; return Resource.GetProperty(name).GetValue(name).ToString(); } public static int Months(this LCA LCAValue) { return LCAValue.EndDate.Month - LCAValue.StartDate.Month + 1 + 12 * (LCAValue.EndDate.Year - LCAValue.StartDate.Year); } public static string MonthLabel(this MonthlyData Value) { if ((Value.StartBase + Value.Index) % 12 == 0) return "12"; return ((Value.StartBase + Value.Index) % 12).ToString(); } public static decimal Multiply(this IEnumerable self) { decimal result = 1m; foreach (var item in self) { result =result* item; } return result; } } }