Skip to content

Commit

Permalink
Removed namespace wrapper around EnumExtensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccallum committed Feb 2, 2016
1 parent 5f90050 commit ca1de00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
4 changes: 2 additions & 2 deletions CoreSystem.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.14.0")]
[assembly: AssemblyFileVersion("1.0.14.0")]
[assembly: AssemblyVersion("1.0.15.0")]
[assembly: AssemblyFileVersion("1.0.15.0")]
4 changes: 2 additions & 2 deletions CoreSystem/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.14.0")]
[assembly: AssemblyFileVersion("1.0.14.0")]
[assembly: AssemblyVersion("1.0.15.0")]
[assembly: AssemblyFileVersion("1.0.15.0")]
35 changes: 14 additions & 21 deletions CoreSystem/Sys/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreSystem.Sys
public static class EnumExtensions
{
public static class EnumExtensions
/// <summary>
/// Gets an attribute on an enum field value
/// </summary>
/// <typeparam name="T">The type of the attribute you want to retrieve</typeparam>
/// <param name="enumVal">The enum value</param>
/// <returns>The attribute of type T that exists on the enum value</returns>
/// <example>string desc = myEnumVariable.GetAttributeOfType<DescriptionAttribute>().Description;</example>
public static T GetAttributeOfType<T>(this Enum enumVal)
where T : Attribute
{
/// <summary>
/// Gets an attribute on an enum field value
/// </summary>
/// <typeparam name="T">The type of the attribute you want to retrieve</typeparam>
/// <param name="enumVal">The enum value</param>
/// <returns>The attribute of type T that exists on the enum value</returns>
/// <example>string desc = myEnumVariable.GetAttributeOfType<DescriptionAttribute>().Description;</example>
public static T GetAttributeOfType<T>(this Enum enumVal)
where T : Attribute
{
var type = enumVal.GetType();
var memInfo = type.GetMember(enumVal.ToString());
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
return (attributes.Length > 0) ? (T)attributes[0] : null;
}
var type = enumVal.GetType();
var memInfo = type.GetMember(enumVal.ToString());
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
return (attributes.Length > 0) ? (T)attributes[0] : null;
}
}

0 comments on commit ca1de00

Please sign in to comment.