From 2d06095447b972c8c7239277428e2c67c8b7ca86 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 25 Feb 2013 22:43:04 -0500 Subject: plugin security fixes and other abstractions --- .../Reflection/TypeMapper.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 MediaBrowser.Server.Implementations/Reflection/TypeMapper.cs (limited to 'MediaBrowser.Server.Implementations/Reflection') diff --git a/MediaBrowser.Server.Implementations/Reflection/TypeMapper.cs b/MediaBrowser.Server.Implementations/Reflection/TypeMapper.cs new file mode 100644 index 000000000..5f411a002 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Reflection/TypeMapper.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Concurrent; +using System.Linq; + +namespace MediaBrowser.Server.Implementations.Reflection +{ + /// + /// Class TypeMapper + /// + public class TypeMapper + { + /// + /// This holds all the types in the running assemblies so that we can de-serialize properly when we don't have strong types + /// + private readonly ConcurrentDictionary _typeMap = new ConcurrentDictionary(); + + /// + /// Gets the type. + /// + /// Name of the type. + /// Type. + /// + public Type GetType(string typeName) + { + if (string.IsNullOrEmpty(typeName)) + { + throw new ArgumentNullException(); + } + + return _typeMap.GetOrAdd(typeName, LookupType); + } + + /// + /// Lookups the type. + /// + /// Name of the type. + /// Type. + private Type LookupType(string typeName) + { + return AppDomain + .CurrentDomain + .GetAssemblies() + .Select(a => a.GetType(typeName, false)) + .FirstOrDefault(t => t != null); + } + } +} -- cgit v1.2.3