Example #1
0
        //public static GeneratorOptionAttribute GetGeneratorAttribute(this MemberInfo mi)
        //{

        //    var genAttr = mi.GetCustomAttributes().FirstOrDefault(x => x.GetType().IsSubclassOf(GetGeneratorAttribute_type));
        //    return (GeneratorOptionAttribute)genAttr;
        //}

        public static Assembly GetAssemblyOfProjectItem(this EnvDTE.ProjectItem pi)
        {
            var path = pi.GetAssemblyPath();

            if (!string.IsNullOrEmpty(path))
            {
                return(Assembly.LoadFrom(path));
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Returns a type from an assembly reference by ProjectItem.Project. Cached.
        /// </summary>
        /// <param name="pi"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Type GetTypeFromProject(this EnvDTE.ProjectItem pi, string typeName)
        {
            var path = pi.GetAssemblyPath();

            if (!(GetTypeFromProject_cache.ContainsKey(path)))
            {
                GetTypeFromProject_cache.Add(path, Assembly.LoadFrom(path));
            }

            var asm  = GetTypeFromProject_cache[path];
            var type = asm.GetType(typeName);

            if (type == null)
            {
                throw new Exception(
                          string.Format("Type {0} not found in assembly {1} at {2}. You may need to rebuild the assembly.",
                                        typeName, asm.FullName, path));
            }
            return(type);
        }