//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); }
/// <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); }
public static string GetDefaultNamespace(this EnvDTE.ProjectItem item) { return(item.ContainingProject.Properties.Item("DefaultNamespace").Value.ToString()); }
public static string GetAssemblyPath(this EnvDTE.ProjectItem pi) { //var assemblyName = pi.ContainingProject.Properties.Cast<Property>().FirstOrDefault(x => x.Name == "AssemblyName").SelectOrDefault(x => x.Value); return(pi.ContainingProject.GetAssemblyPath()); }