コード例 #1
0
        /// <summary>
        ///     Helper method to get only one specific type by its full qualified type name.
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static TypeDefinition GetTypeByName(AssemblyDefinition assembly, string typeName)
        {
            var types = new TypeQuery().GetTypes(assembly);

            foreach (var type in types)
            {
                if (type.FullName == typeName)
                {
                    return(type);
                }
            }

            return(null);
        }
コード例 #2
0
        public List <TypeQuery> GetQueries(string typeQueries, TypeQueryMode additionalFlags)
        {
            if (typeQueries == null)
            {
                throw new ArgumentNullException("typeQueries");
            }

            var trimedQuery = typeQueries.Trim();

            if (trimedQuery == "")
            {
                throw new ArgumentException("typeQueries was an empty string");
            }

            var queries = trimedQuery.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            var ret = new List <TypeQuery>();

            foreach (var query in queries)
            {
                var m = myQueryParser.Match(query);
                if (!m.Success)
                {
                    throw new ArgumentException(string.Format("The type query \"{0}\" is not of the form [public|internal|class|interface|struct|enum|nocompiler|api] typename", query));
                }

                var mode = this.GetQueryMode(m);
                var nameSpaceTypeName = this.SplitNameSpaceAndType(m.Groups["typeName"].Value);
                var typeQuery         = new TypeQuery(mode, nameSpaceTypeName.Key, nameSpaceTypeName.Value);
                if (typeQuery.SearchMode == TypeQueryMode.None)
                {
                    typeQuery.SearchMode |= additionalFlags;
                }
                ret.Add(typeQuery);
            }

            return(ret);
        }