/// <summary>Adds the given text as a reference. Must also include the assembly unless it is in 'this' one.</summary>
		/// <param name="text">The reference to add, e.g. "Nitro" or "System.System".</param>
		protected void AddReference(string text){
			if(DefaultReferences==null){
				DefaultReferences=new List<CodeReference>();
			}
			CodeReference codeRef=new CodeReference(text);
			DefaultReferences.Add(codeRef);
		}
예제 #2
0
        /// <summary>Adds the given text as a reference. Must also include the assembly unless it is in 'this' one.</summary>
        /// <param name="text">The reference to add, e.g. "Nitro" or "System.System".</param>
        protected void AddReference(string text)
        {
            if (DefaultReferences == null)
            {
                DefaultReferences = new List <CodeReference>();
            }
            CodeReference codeRef = new CodeReference(text);

            DefaultReferences.Add(codeRef);
        }
예제 #3
0
        /// <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);
        }