- Timestamp:
- 03/15/12 09:11:17 (13 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries
-
branches/HeuristicLab.TimeSeries/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs
r7268 r7615 75 75 foreach (Type t in GetTypes(type)) { 76 76 object instance = null; 77 try { instance = Activator.CreateInstance(t); } 78 catch { } 77 try { instance = Activator.CreateInstance(t); } catch { } 79 78 if (instance != null) instances.Add(instance); 80 79 } … … 126 125 var assemblyTypes = assembly.GetTypes(); 127 126 128 var buildTypes = from t in assemblyTypes 127 var buildTypes = from t in assembly.GetTypes() 128 where CheckTypeCompatibility(type, t) 129 129 where !IsNonDiscoverableType(t) 130 where CheckTypeCompatibility(type, t)131 where onlyInstantiable == false ||(!t.IsAbstract && !t.IsInterface && !t.HasElementType)130 where onlyInstantiable == false || 131 (!t.IsAbstract && !t.IsInterface && !t.HasElementType) 132 132 select BuildType(t, type); 133 133 … … 135 135 where includeGenericTypeDefinitions || !t.IsGenericTypeDefinition 136 136 select t; 137 } 138 catch (TypeLoadException) { 137 } catch (TypeLoadException) { 139 138 return Enumerable.Empty<Type>(); 140 } 141 catch (ReflectionTypeLoadException) { 139 } catch (ReflectionTypeLoadException) { 142 140 return Enumerable.Empty<Type>(); 143 141 } … … 152 150 return true; 153 151 if (type.IsGenericType && other.IsGenericType) { 152 var otherGenericArguments = other.GetGenericArguments(); 153 var typeGenericArguments = type.GetGenericArguments(); 154 155 //check type arguments count 156 if (otherGenericArguments.Length != typeGenericArguments.Length) 157 return false; 158 159 //check type arguments & constraints 160 int i = 0; 161 foreach (var genericArgument in typeGenericArguments) { 162 if (otherGenericArguments[i].IsGenericParameter) { 163 foreach (var constraint in otherGenericArguments[i].GetGenericParameterConstraints()) 164 if (!constraint.IsAssignableFrom(genericArgument)) return false; 165 } else if (genericArgument != otherGenericArguments[i]) return false; 166 i++; 167 } 168 //check types 154 169 try { 155 if (type.IsAssignableFrom(other.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments()))) 170 var otherGenericTypeDefinition = other.GetGenericTypeDefinition(); 171 if (type.IsAssignableFrom(otherGenericTypeDefinition.MakeGenericType(typeGenericArguments))) 156 172 return true; 157 } 158 catch (Exception) { } 173 } catch (Exception) { } 159 174 } 160 175 return false; -
branches/HeuristicLab.TimeSeries/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs
r7268 r7615 235 235 PluginDescription pluginDesc = (PluginDescription)pluginDescription; 236 236 return from asm in AppDomain.CurrentDomain.GetAssemblies() 237 where ! IsDynamicAssembly(asm)237 where !asm.IsDynamic && !string.IsNullOrEmpty(asm.Location) 238 238 where pluginDesc.AssemblyLocations.Any(location => location.Equals(Path.GetFullPath(asm.Location), StringComparison.CurrentCultureIgnoreCase)) 239 239 from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions) … … 249 249 } 250 250 return result; 251 }252 253 private static bool IsDynamicAssembly(Assembly asm) {254 return (asm is System.Reflection.Emit.AssemblyBuilder) || string.IsNullOrEmpty(asm.Location);255 251 } 256 252 … … 266 262 private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable, bool includeGenericTypeDefinitions) { 267 263 var buildTypes = from t in assembly.GetTypes() 264 where CheckTypeCompatibility(type, t) 268 265 where !IsNonDiscoverableType(t) 269 where CheckTypeCompatibility(type, t)270 266 where onlyInstantiable == false || 271 267 (!t.IsAbstract && !t.IsInterface && !t.HasElementType) … … 286 282 return true; 287 283 if (type.IsGenericType && other.IsGenericType) { 284 var otherGenericArguments = other.GetGenericArguments(); 285 var typeGenericArguments = type.GetGenericArguments(); 286 287 //check type arguments count 288 if (otherGenericArguments.Length != typeGenericArguments.Length) 289 return false; 290 291 //check type arguments & constraints 292 int i = 0; 293 foreach (var genericArgument in typeGenericArguments) { 294 if (otherGenericArguments[i].IsGenericParameter) { 295 foreach (var constraint in otherGenericArguments[i].GetGenericParameterConstraints()) 296 if (!constraint.IsAssignableFrom(genericArgument)) return false; 297 } else if (genericArgument != otherGenericArguments[i]) return false; 298 i++; 299 } 300 //check types 288 301 try { 289 if (type.IsAssignableFrom(other.GetGenericTypeDefinition().MakeGenericType(type.GetGenericArguments()))) 302 var otherGenericTypeDefinition = other.GetGenericTypeDefinition(); 303 if (type.IsAssignableFrom(otherGenericTypeDefinition.MakeGenericType(typeGenericArguments))) 290 304 return true; 291 305 }
Note: See TracChangeset
for help on using the changeset viewer.