/// <summary> /// Find the type from the name supplied /// </summary> /// <param name="typeName">[typeName] or [typeName, assemblyName]</param> /// <returns></returns> public static Type FindType(string typeName) { Type type = null; if (TypeCache.TryGetValue(typeName, out type)) { return(type); } #if !SILVERLIGHT type = Type.GetType(typeName); #endif if (type == null) { var typeDef = new AssemblyTypeDefinition(typeName); type = !string.IsNullOrEmpty(typeDef.AssemblyName) ? FindType(typeDef.TypeName, typeDef.AssemblyName) : FindTypeFromLoadedAssemblies(typeDef.TypeName); } Dictionary <string, Type> snapshot, newCache; do { snapshot = TypeCache; newCache = new Dictionary <string, Type>(TypeCache); newCache[typeName] = type; } while (!ReferenceEquals( Interlocked.CompareExchange(ref TypeCache, newCache, snapshot), snapshot)); return(type); }
/// <summary> /// Find the type from the name supplied /// </summary> /// <param name="typeName">[typeName] or [typeName, assemblyName]</param> /// <returns></returns> public static Type FindType(string typeName) { var typeDef = new AssemblyTypeDefinition(typeName); if (!string.IsNullOrEmpty(typeDef.AssemblyName)) { return(FindType(typeDef.TypeName, typeDef.AssemblyName)); } else { return(FindTypeFromLoadedAssemblies(typeDef.TypeName)); } }
/// <summary> /// Find the type from the name supplied /// </summary> /// <param name="typeName">[typeName] or [typeName, assemblyName]</param> /// <returns></returns> public static Type FindType(string typeName) { #if !SILVERLIGHT var type = Type.GetType(typeName); if (type != null) { return(type); } #endif var typeDef = new AssemblyTypeDefinition(typeName); if (!String.IsNullOrEmpty(typeDef.AssemblyName)) { return(FindType(typeDef.TypeName, typeDef.AssemblyName)); } else { return(FindTypeFromLoadedAssemblies(typeDef.TypeName)); } }
/// <summary> /// Find the type from the name supplied /// </summary> /// <param name="typeName">[typeName] or [typeName, assemblyName]</param> /// <returns></returns> public static Type FindType(string typeName) { Type type = null; if (TypeCache.TryGetValue(typeName, out type)) { return(type); } #if !SILVERLIGHT type = Type.GetType(typeName); #endif if (type == null) { var typeDef = new AssemblyTypeDefinition(typeName); type = !string.IsNullOrEmpty(typeDef.AssemblyName) ? FindType(typeDef.TypeName, typeDef.AssemblyName) #if !NETCF : FindTypeFromLoadedAssemblies(typeDef.TypeName);