forked from Particular/ServiceInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflectionHelper.cs
More file actions
27 lines (23 loc) · 840 Bytes
/
ReflectionHelper.cs
File metadata and controls
27 lines (23 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.ComponentModel;
using System.Reflection;
namespace NServiceBus.Profiler.Desktop.ExtensionMethods
{
public static class ReflectionHelper
{
public static T GetAttribute<T>(this ICustomAttributeProvider provider, bool inherit = false)
where T : class
{
var attrib = provider.GetCustomAttributes(typeof (T), inherit);
if(attrib.Length > 0)
return (T)attrib[0];
return null;
}
public static string GetDescription(this Enum value)
{
var field = value.GetType().GetField(value.ToString());
var attribute = field.GetAttribute<DescriptionAttribute>();
return attribute != null ? attribute.Description : value.ToString();
}
}
}