forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeExtensions.cs
More file actions
31 lines (27 loc) · 1.01 KB
/
Copy pathTypeExtensions.cs
File metadata and controls
31 lines (27 loc) · 1.01 KB
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
28
29
30
31
using System;
using System.Collections.Generic;
using System.Reflection;
namespace ServiceStack.Common
{
public static class TypeExtensions
{
private static readonly Dictionary<Type, List<string>> TypePropertyNamesMap = new Dictionary<Type, List<string>>();
public static List<string> GetPropertyNames(this Type type)
{
lock (TypePropertyNamesMap)
{
List<string> propertyNames;
if (!TypePropertyNamesMap.TryGetValue(type, out propertyNames))
{
propertyNames = Extensions.EnumerableExtensions.ConvertAll(type.GetProperties(), x => x.Name);
TypePropertyNamesMap[type] = propertyNames;
}
return propertyNames;
}
}
public static List<T> ToAttributes<T>(this Type type) where T : Attribute
{
return type.GetCustomAttributes(typeof(T), true).SafeConvertAll(x => (T)x);
}
}
}