~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/ServiceStack/src/ServiceStack.Common/TypeExtensions.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.Reflection;
 
4
 
 
5
namespace ServiceStack.Common
 
6
{
 
7
    public static class TypeExtensions
 
8
    {
 
9
        private static readonly Dictionary<Type, List<string>> TypePropertyNamesMap = new Dictionary<Type, List<string>>();
 
10
 
 
11
        public static List<string> GetPropertyNames(this Type type)
 
12
        {
 
13
            lock (TypePropertyNamesMap)
 
14
            {
 
15
                List<string> propertyNames;
 
16
                if (!TypePropertyNamesMap.TryGetValue(type, out propertyNames))
 
17
                {
 
18
                    propertyNames = Extensions.EnumerableExtensions.ConvertAll(type.GetProperties(), x => x.Name);
 
19
                    TypePropertyNamesMap[type] = propertyNames;
 
20
                }
 
21
                return propertyNames;
 
22
            }
 
23
        }
 
24
 
 
25
        public static List<T> ToAttributes<T>(this Type type) where T : Attribute
 
26
        {
 
27
            return type.GetCustomAttributes(typeof(T), true).SafeConvertAll(x => (T)x);
 
28
        }
 
29
 
 
30
#if !SILVERLIGHT
 
31
        public static string GetAssemblyPath(this Type source)
 
32
        {
 
33
            var assemblyUri =
 
34
                new Uri(source.Assembly.EscapedCodeBase);
 
35
 
 
36
            return assemblyUri.LocalPath;
 
37
        }
 
38
#endif
 
39
    }
 
40
}