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
| public static Dictionary<int, string> GetEnumDictionary<T>() where T : struct | |
| { | |
| if (!typeof(T).IsEnum) | |
| throw new ArgumentException("T is not an Enum type"); | |
| return Enum.GetValues(typeof(T)) | |
| .Cast<object>() | |
| .ToDictionary(k => (int)k, v => ((Enum)v).GetDescription()); | |
| } |
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
| public static string GetDescription(this Enum enumeration) | |
| { | |
| string value = enumeration.ToString(); | |
| Type enumType = enumeration.GetType(); | |
| var descAttribute = (DescriptionAttribute[])enumType | |
| .GetField(value) | |
| .GetCustomAttributes(typeof(DescriptionAttribute), false); | |
| return descAttribute.Length > 0 ? descAttribute[0].Description : value; | |
| } |
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
| public static IEnumerable<Control> AllChildControls(this Control control) | |
| { | |
| var children = control.Controls.Cast<Control>(); | |
| return children.SelectMany(c => AllChildControls(c)).Concat(children); | |
| } |
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
| public static bool IsLastDayOfTheMonth(this DateTime dateTime) | |
| { | |
| return dateTime.Month != dateTime.AddDays(1).Month; | |
| } |
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
| public static Guid ToGuid(this int value) | |
| { | |
| byte[] bytes = new byte[16]; | |
| BitConverter.GetBytes(value).CopyTo(bytes, 0); | |
| return new Guid(bytes); | |
| } |