private static WholeProgramSearchQuery CreateQueryForIdentifier(string identifier)
        {
            WholeProgramSearchQuery query;

            // assemblyname!M:Foo.Bar.GetBlam(System.String)

            string[] components = identifier.Split('!');

            if (components.Count() == 2)
            {
                query = new WholeProgramSearchQuery()
                {
                    AssemblySpecifier = components[0], DefinitionSpecifier = components[1]
                };
            }
            else if (components.Count() == 1)
            {
                query = new WholeProgramSearchQuery()
                {
                    DefinitionSpecifier = components[0]
                };
            }
            else
            {
                throw new Exception("Malformed type identifier: " + identifier);
            }

            return(query);
        }
        private static ISet <ITypeDefinition> LookupTypesMatchingRegexpIdentifier(string identifier, WholeProgram wholeProgram)
        {
            WholeProgramSearchQuery query = CreateQueryForIdentifier(identifier);

            query.PerformRegexpMatch = true;

            return(LookupTypesMatchingQuery(query, wholeProgram));
        }
        private static ISet <ITypeDefinition> LookupTypesMatchingQuery(WholeProgramSearchQuery query, WholeProgram wholeProgram)
        {
            ISet <ITypeDefinition> types = wholeProgram.FindTypesMatchingWholeProgramQuery(query);

            if (types.Count() > 0)
            {
                return(types);
            }
            else
            {
                // Really should have function that turns query into a human readable string
                throw new Exception("Couldn't find any types matching query: " + query.AssemblySpecifier + "!" + query.DefinitionSpecifier);
            }
        }
        private static ISet <ITypeDefinition> LookupTypesWithIdentifier(string identifier, WholeProgram wholeProgram)
        {
            WholeProgramSearchQuery query = CreateQueryForIdentifier(identifier);

            ISet <ITypeDefinition> types = wholeProgram.FindTypesMatchingWholeProgramQuery(query);

            if (types.Count() > 0)
            {
                return(types);
            }
            else
            {
                throw new Exception("Couldn't find type with identifier: " + identifier);
            }
        }
        private static ITypeDefinition LookupExactTypeWithIdentifier(string identifier, WholeProgram wholeProgram)
        {
            WholeProgramSearchQuery query = CreateQueryForIdentifier(identifier);

            ISet <ITypeDefinition> types = LookupTypesMatchingQuery(query, wholeProgram);

            if (types.Count() == 1)
            {
                return(types.First());
            }
            else
            {
                throw new Exception("Couldn't find unique type with identifier: " + identifier + " (found " + types.Count() + ")");
            }
        }
        private static IFieldDefinition LookupFieldWithIdentifier(string identifier, WholeProgram wholeProgram)
        {
            WholeProgramSearchQuery query = CreateQueryForIdentifier(identifier);

            ISet <IFieldDefinition> fields = wholeProgram.FindFieldsMatchingWholeProgramQuery(query);

            if (fields.Count() == 1)
            {
                return(fields.First());
            }
            else if (fields.Count() > 1)
            {
                throw new Exception("Couldn't find unique field with identifier " + identifier + " (found " + fields.Count() + ")");
            }
            else
            {
                throw new Exception("Couldn't find fields with identifier: " + identifier);
            }
        }