public static Type GetTypeFromConfigString(string name, NamedConfigCategory category) { Type type = Type.GetType(name); if (type != null) { return(type); } foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) { var cache = cached_named_config_types.FirstOrDefault(c => c.Name == name && c.Category == category); if (cache != null) { return(cache.Type); } if ((type = ass.GetType(name)) != null) { return(type); } if (cached_assemblies.Contains(ass)) { continue; } #if NET_4_0 if (!ass.IsDynamic) #endif cached_assemblies.Add(ass); foreach (var t in ass.GetTypes()) { if (cached_named_config_types.Any(ct => ct.Type == t)) { continue; } NamedConfigType c = null; var sca = t.GetCustomAttribute <ServiceContractAttribute> (false); if (sca != null && !String.IsNullOrEmpty(sca.ConfigurationName)) { c = new NamedConfigType() { Category = NamedConfigCategory.Contract, Name = sca.ConfigurationName, Type = t }; cached_named_config_types.Add(c); } // If we need more category, add to here. if (c != null && c.Name == name && c.Category == category) { cache = c; // do not break and continue caching (as the assembly is being cached) } } if (cache != null) { return(cache.Type); } } return(null); }
public static Type GetTypeFromConfigString (string name, NamedConfigCategory category) { Type type = Type.GetType (name); if (type != null) return type; foreach (var ass in AppDomain.CurrentDomain.GetAssemblies ()) { var cache = cached_named_config_types.FirstOrDefault (c => c.Name == name && c.Category == category); if (cache != null) return cache.Type; if ((type = ass.GetType (name)) != null) return type; if (cached_assemblies.Contains (ass)) continue; #if NET_4_0 if (!ass.IsDynamic) #endif cached_assemblies.Add (ass); foreach (var t in ass.GetTypes ()) { if (cached_named_config_types.Any (ct => ct.Type == t)) continue; NamedConfigType c = null; var sca = t.GetCustomAttribute<ServiceContractAttribute> (false); if (sca != null && !String.IsNullOrEmpty (sca.ConfigurationName)) { c = new NamedConfigType () { Category = NamedConfigCategory.Contract, Name = sca.ConfigurationName, Type = t }; cached_named_config_types.Add (c); } // If we need more category, add to here. if (c != null && c.Name == name && c.Category == category) cache = c; // do not break and continue caching (as the assembly is being cached) } if (cache != null) return cache.Type; } return null; }