GetAssemblies
How do I use Get Assemblies
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
978 | System.Reflection.Assembly[] AS = System.AppDomain.CurrentDomain.GetAssemblies(); | 1 |
301 | var errorTypes = from a in AppDomain.CurrentDomain.GetAssemblies() | 2 |
File name: PhotonEditor.cs
Copy
975 public static System.Type[] GetAllSubTypesInScripts(System.Type aBaseClass)
976 {
977 var result = new System.Collections.Generic.List
978 System.Reflection.Assembly[] AS = System.AppDomain.CurrentDomain.GetAssemblies();
979 foreach (var A in AS)
980 {
981 // this skips all but the Unity-scripted assemblies for RPC-list creation. You could remove this to search all assemblies in project
982 if (!A.FullName.StartsWith("Assembly-"))
983 {
984 // Debug.Log("Skipping Assembly: " + A);
985 continue;
986 }
987
988 //Debug.Log("Assembly: " + A.FullName);
989 System.Type[] types = A.GetTypes();
990 foreach (var T in types)
991 {
992 if (T.IsSubclassOf(aBaseClass))
993 result.Add(T);
994 }
995 }
996 return result.ToArray();
997 }
File name: ImportTiled2Unity.Mesh.cs
Copy
298 private IList299 {
300 // Report an error for ICustomTiledImporter classes that don't have the CustomTiledImporterAttribute
301 var errorTypes = from a in AppDomain.CurrentDomain.GetAssemblies()
302 from t in a.GetTypes()
303 where typeof(ICustomTiledImporter).IsAssignableFrom(t)
304 where !t.IsAbstract
305 where Attribute.GetCustomAttribute(t, typeof(CustomTiledImporterAttribute)) == null
306 select t;
307 foreach (var t in errorTypes)
308 {
309 Debug.LogError(String.Format("ICustomTiledImporter type '{0}' is missing CustomTiledImporterAttribute", t));
310 }
311
312 // Find all the types with the CustomTiledImporterAttribute, instantiate them, and give them a chance to customize our prefab
313 var types = from a in AppDomain.CurrentDomain.GetAssemblies()
314 from t in a.GetTypes()
315 where typeof(ICustomTiledImporter).IsAssignableFrom(t)
316 where !t.IsAbstract
317 from attr in Attribute.GetCustomAttributes(t, typeof(CustomTiledImporterAttribute))
318 let custom = attr as CustomTiledImporterAttribute
319 orderby custom.Order
320 select t;
321
322 var instances = types.Select(t => (ICustomTiledImporter)Activator.CreateInstance(t));
323 return instances.ToList();
324 }
GetAssemblies 121 lượt xem
Gõ tìm kiếm nhanh...