/// <summary>Sets up the compiler.</summary> public static void Setup() { if (Started) { return; } Started = true; Type[] allTypes = Assembly.GetExecutingAssembly().GetTypes(); Type operatorT = typeof(Operator); // For each type.. for (int i = allTypes.Length - 1; i >= 0; i--) { Type type = allTypes[i]; if (type.IsSubclassOf(operatorT)) { // Register it as being an available type of operator. Operator.Add((Operator)Activator.CreateInstance(type)); } } TypeAliases.Setup(); }
/// <summary>Searches for all the types with the given name by first performing an alias lookup.</summary> /// <param name="name">The type name to search for.</param> /// <returns>A system type if found; null otherwise.</returns> public List <Type> GetTypes(string name) { // Alias lookup - is name an alias? (e.g. 'int') Type type = TypeAliases.Find(name); List <Type> results = null; if (type != null) { // It sure was - add it: results = new List <Type>(); results.Add(type); } // Check if we can straight get the type by this name. // Go hunting - can we find typeName anywhere? type = Type.GetType(name, false, true); if (type != null) { // Wohoo that was easy! if (results == null) { results = new List <Type>(); } results.Add(type); } // Start looking around in our Referenced namespaces to find this type. // This is done because e.g. Socket is named System.Net.Socket in the System.Net namespace. // As the reference knows which assembly to look in, these are quick to handle. if (References != null) { foreach (CodeReference reference in References) { type = reference.GetType(name); if (type != null) { if (results == null) { results = new List <Type>(); } results.Add(type); } } } // It could also be in an assembly on it's own without a namespace. // Lets look for that next. // Make sure all available assemblies are setup for use: CodeReference.Setup(); // And check in each one: foreach (KeyValuePair <string, CodeAssembly> assembly in CodeReference.Assemblies) { if (assembly.Value.Current || assembly.Value.NitroAOT) { // This was the first thing we checked, or is a Nitro assembly - skip. continue; } type = assembly.Value.GetType(name); if (type != null) { if (results == null) { results = new List <Type>(); } results.Add(type); } } return(results); }