Skip to content

Commit

Permalink
refactored all the overloads in TypeLibsAPI, plus added more for supp…
Browse files Browse the repository at this point in the history
…orting IVBComponent directly
  • Loading branch information
WaynePhillipsEA committed Jan 24, 2018
1 parent 2755900 commit 93edd54
Showing 1 changed file with 149 additions and 42 deletions.
191 changes: 149 additions & 42 deletions Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibsAPI.cs
Expand Up @@ -42,85 +42,115 @@ public static bool CompileProject(IVBE ide, string projectName)
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return typeLibs.FindTypeLib(projectName).CompileProject();
return CompileProject(typeLibs.FindTypeLib(projectName));
}
}
public static bool CompileProject(IVBProject project)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return typeLib.CompileProject();
return CompileProject(typeLib);
}
}
public static bool CompileProject(TypeLibWrapper projectTypeLib)
{
return projectTypeLib.CompileProject();
}

// Compile a module in a VBE project, returning success (true)/failure (false)
// NOTE: This will only return success if ALL modules that this module depends on compile successfully
public static bool CompileComponent(IVBE ide, string projectName, string componentName)
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return typeLibs.FindTypeLib(projectName).FindTypeInfo(componentName).CompileComponent();
return CompileComponent(typeLibs.FindTypeLib(projectName), componentName);
}
}
public static bool CompileComponent(IVBProject project, string componentName)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return typeLib.FindTypeInfo(componentName).CompileComponent();
return CompileComponent(typeLib, componentName);
}
}
public static bool CompileComponent(TypeLibWrapper projectTypeLib, string componentName)
{
return CompileComponent(projectTypeLib.FindTypeInfo(componentName));
}
public static bool CompileComponent(TypeInfoWrapper componentTypeInfo)
{
return componentTypeInfo.CompileComponent();
}
public static bool CompileComponent(IVBComponent component)
{
return CompileComponent(component.ParentProject, component.Name);
}

public static object ExecuteCode(IVBE ide, string projectName, string standardModuleName, string procName, object[] args = null)
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return typeLibs.FindTypeLib(projectName).FindTypeInfo(standardModuleName)
.StdModExecute(procName, Reflection.BindingFlags.InvokeMethod, args);
return ExecuteCode(typeLibs.FindTypeLib(projectName), standardModuleName, procName, args);
}
}
public static object ExecuteCode(IVBProject project, string standardModuleName, string procName, object[] args = null)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return typeLib.FindTypeInfo(standardModuleName)
.StdModExecute(procName, Reflection.BindingFlags.InvokeMethod, args);
return ExecuteCode(typeLib, standardModuleName, procName, args);
}
}

public static object ExecuteCode(TypeLibWrapper projectTypeLib, string standardModuleName, string procName, object[] args = null)
{
return ExecuteCode(projectTypeLib.FindTypeInfo(standardModuleName), procName, args);
}
public static object ExecuteCode(IVBComponent component, string procName, object[] args = null)
{
return ExecuteCode(component.ParentProject, component.Name, procName, args);
}
public static object ExecuteCode(TypeInfoWrapper standardModuleTypeInfo, string procName, object[] args = null)
{
return standardModuleTypeInfo.StdModExecute(procName, Reflection.BindingFlags.InvokeMethod, args);
}

// returns the raw conditional arguments string, e.g. "foo = 1 : bar = 2"
public static string GetProjectConditionalCompilationArgsRaw(IVBE ide, string projectName)
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return typeLibs.FindTypeLib(projectName).ConditionalCompilationArguments;
return GetProjectConditionalCompilationArgsRaw(typeLibs.FindTypeLib(projectName));
}
}
public static string GetProjectConditionalCompilationArgsRaw(IVBProject project)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return typeLib.ConditionalCompilationArguments;
return GetProjectConditionalCompilationArgsRaw(typeLib);
}
}
public static string GetProjectConditionalCompilationArgsRaw(TypeLibWrapper projectTypeLib)
{
return projectTypeLib.ConditionalCompilationArguments;
}

// return the parsed conditional arguments string as a Dictionary<string, string>
public static Dictionary<string, string> GetProjectConditionalCompilationArgs(IVBE ide, string projectName)
{
var args = GetProjectConditionalCompilationArgsRaw(ide, projectName);

if (args.Length > 0)
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
string[] argsArray = args.Split(new[] { ':' });
return argsArray.Select(item => item.Split('=')).ToDictionary(s => s[0], s => s[1]);
return GetProjectConditionalCompilationArgs(typeLibs.FindTypeLib(projectName));
}
else
}
public static Dictionary<string, string> GetProjectConditionalCompilationArgs(IVBProject project)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return new Dictionary<string, string>();
return GetProjectConditionalCompilationArgs(typeLib);
}
}
public static Dictionary<string, string> GetProjectConditionalCompilationArgs(IVBProject project)
public static Dictionary<string, string> GetProjectConditionalCompilationArgs(TypeLibWrapper projectTypeLib)
{
string args = GetProjectConditionalCompilationArgsRaw(project);
string args = GetProjectConditionalCompilationArgsRaw(projectTypeLib);

if (args.Length > 0)
{
Expand All @@ -138,93 +168,168 @@ public static void SetProjectConditionalCompilationArgsRaw(IVBE ide, string proj
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
typeLibs.FindTypeLib(projectName).ConditionalCompilationArguments = newConditionalArgs;
SetProjectConditionalCompilationArgsRaw(typeLibs.FindTypeLib(projectName), newConditionalArgs);
}
}
public static void SetProjectConditionalCompilationArgsRaw(IVBProject project, string newConditionalArgs)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
typeLib.ConditionalCompilationArguments = newConditionalArgs;
SetProjectConditionalCompilationArgsRaw(typeLib, newConditionalArgs);
}
}
public static void SetProjectConditionalCompilationArgsRaw(TypeLibWrapper projectTypeLib, string newConditionalArgs)
{
projectTypeLib.ConditionalCompilationArguments = newConditionalArgs;
}

// sets the conditional arguments string via a Dictionary<string, string>
public static void SetProjectConditionalCompilationArgs(IVBE ide, string projectName, Dictionary<string, string> newConditionalArgs)
{
var rawArgsString = string.Join(" : ", newConditionalArgs.Select(x => x.Key + " = " + x.Value));
SetProjectConditionalCompilationArgsRaw(ide, projectName, rawArgsString);
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
SetProjectConditionalCompilationArgs(typeLibs.FindTypeLib(projectName), newConditionalArgs);
}
}
public static void SetProjectConditionalCompilationArgs(IVBProject project, Dictionary<string, string> newConditionalArgs)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
SetProjectConditionalCompilationArgs(typeLib, newConditionalArgs);
}
}
public static void SetProjectConditionalCompilationArgs(TypeLibWrapper projectTypeLib, Dictionary<string, string> newConditionalArgs)
{
var rawArgsString = string.Join(" : ", newConditionalArgs.Select(x => x.Key + " = " + x.Value));
SetProjectConditionalCompilationArgsRaw(project, rawArgsString);
SetProjectConditionalCompilationArgsRaw(projectTypeLib, rawArgsString);
}

public static bool IsExcelWorkbook(IVBE ide, string projectName, string className)
{
return DoesClassImplementInterface(ide, projectName, className, "Excel", "_Workbook");
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return IsExcelWorkbook(typeLibs.FindTypeLib(projectName), className);
}
}
public static bool IsExcelWorkbook(IVBProject project, string className)
{
return DoesClassImplementInterface(project, className, "Excel", "_Workbook");
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return IsExcelWorkbook(typeLib, className);
}
}
public static bool IsExcelWorkbook(IVBComponent component)
{
return IsExcelWorkbook(component.ParentProject, component.Name);
}
public static bool IsExcelWorkbook(TypeLibWrapper projectTypeLib, string className)
{
return DoesClassImplementInterface(projectTypeLib, className, "Excel", "_Workbook");
}

public static bool IsExcelWorksheet(IVBE ide, string projectName, string className)
{
return DoesClassImplementInterface(ide, projectName, className, "Excel", "_Worksheet");
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return IsExcelWorksheet(typeLibs.FindTypeLib(projectName), className);
}
}
public static bool IsExcelWorksheet(IVBProject project, string className)
{
return DoesClassImplementInterface(project, className, "Excel", "_Worksheet");
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return IsExcelWorksheet(typeLib, className);
}
}
public static bool IsExcelWorksheet(IVBComponent component)
{
return IsExcelWorksheet(component.ParentProject, component.Name);
}
public static bool IsExcelWorksheet(TypeLibWrapper projectTypeLib, string className)
{
return DoesClassImplementInterface(projectTypeLib, className, "Excel", "_Worksheet");
}

public static bool DoesClassImplementInterface(IVBE ide, string projectName, string className, string typeLibName, string interfaceName)
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return typeLibs.FindTypeLib(projectName).FindTypeInfo(className).DoesImplement(typeLibName, interfaceName);
return DoesClassImplementInterface(typeLibs.FindTypeLib(projectName), className, typeLibName, interfaceName);
}
}
public static bool DoesClassImplementInterface(IVBProject project, string className, string typeLibName, string interfaceName)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return typeLib.FindTypeInfo(className).DoesImplement(typeLibName, interfaceName);
return DoesClassImplementInterface(typeLib.FindTypeInfo(className), typeLibName, interfaceName);
}
}
public static bool DoesClassImplementInterface(TypeLibWrapper projectTypeLib, string className, string typeLibName, string interfaceName)
{
return DoesClassImplementInterface(projectTypeLib.FindTypeInfo(className), typeLibName, interfaceName);
}
public static bool DoesClassImplementInterface(IVBComponent component, string typeLibName, string interfaceName)
{
return DoesClassImplementInterface(component.ParentProject, component.Name, typeLibName, interfaceName);
}
public static bool DoesClassImplementInterface(TypeInfoWrapper classTypeInfo, string typeLibName, string interfaceName)
{
return classTypeInfo.DoesImplement(typeLibName, interfaceName);
}

public static bool DoesClassImplementInterface(IVBE ide, string projectName, string className, Guid interfaceIID)
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return typeLibs.FindTypeLib(projectName).FindTypeInfo(className).DoesImplement(interfaceIID);
return DoesClassImplementInterface(typeLibs.FindTypeLib(projectName), className, interfaceIID);
}
}
public static bool DoesClassImplementInterface(IVBProject project, string className, Guid interfaceIID)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return typeLib.FindTypeInfo(className).DoesImplement(interfaceIID);
return DoesClassImplementInterface(typeLib.FindTypeInfo(className), interfaceIID);
}
}
public static bool DoesClassImplementInterface(TypeLibWrapper projectTypeLib, string className, Guid interfaceIID)
{
return DoesClassImplementInterface(projectTypeLib.FindTypeInfo(className), interfaceIID);
}
public static bool DoesClassImplementInterface(IVBComponent component, Guid interfaceIID)
{
return DoesClassImplementInterface(component.ParentProject, component.Name, interfaceIID);
}
public static bool DoesClassImplementInterface(TypeInfoWrapper classTypeInfo, Guid interfaceIID)
{
return classTypeInfo.DoesImplement(interfaceIID);
}

public static string GetUserFormControlType(IVBE ide, string projectName, string userFormName, string controlName)
{
using (var typeLibs = new VBETypeLibsAccessor(ide))
{
return typeLibs.FindTypeLib(projectName).FindTypeInfo(userFormName)
.GetImplementedTypeInfo("FormItf").GetControlType(controlName).Name;
return GetUserFormControlType(typeLibs.FindTypeLib(projectName), userFormName, controlName);
}
}
public static string GetUserFormControlType(IVBProject project, string userFormName, string controlName)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
return typeLib.FindTypeInfo(userFormName)
.GetImplementedTypeInfo("FormItf").GetControlType(controlName).Name;
return GetUserFormControlType(typeLib, userFormName, controlName);
}
}
public static string GetUserFormControlType(TypeLibWrapper projectTypeLib, string userFormName, string controlName)
{
return GetUserFormControlType(projectTypeLib.FindTypeInfo(userFormName), controlName);
}
public static string GetUserFormControlType(IVBComponent component, string controlName)
{
return GetUserFormControlType(component.ParentProject, component.Name, controlName);
}
public static string GetUserFormControlType(TypeInfoWrapper userFormTypeInfo, string controlName)
{
return userFormTypeInfo.GetImplementedTypeInfo("FormItf").GetControlType(controlName).Name;
}

public static string DocumentAll(IVBE ide)
{
Expand All @@ -244,12 +349,14 @@ public static string DocumentAll(IVBProject project)
{
using (var typeLib = TypeLibWrapper.FromVBProject(project))
{
var documenter = new TypeLibDocumenter();

documenter.AddTypeLib(typeLib);

return documenter.ToString();
return DocumentAll(typeLib);
}
}
public static string DocumentAll(TypeLibWrapper projectTypeLib)
{
var documenter = new TypeLibDocumenter();
documenter.AddTypeLib(projectTypeLib);
return documenter.ToString();
}
}
}

0 comments on commit 93edd54

Please sign in to comment.