Skip to content

Commit 75bf555

Browse files
lots of nits
1 parent 80b5bfa commit 75bf555

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibs.cs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
// TODO add memory address validation in ReadStructureSafe
1313
// TODO split into TypeInfos.cs
14+
// references expose the raw ITypeLibs
1415

1516
/// <summary>
1617
/// For usage examples, please see VBETypeLibsAPI
@@ -106,6 +107,8 @@ public class RestrictComInterfaceByAggregation<T> : ICustomQueryInterface, IDisp
106107
/// </summary>
107108
/// <param name="outerObject">The object that needs interface requests filtered</param>
108109
/// <param name="queryForType">determines whether we call QueryInterface for the interface or not</param>
110+
/// <remarks>if the passed in outerObject is known to point to the correct vtable for the interface, then queryForType can be false</remarks>
111+
/// <returns>if outerObject is IntPtr.Zero, then a null wrapper, else an aggregated wrapper</returns>
109112
public RestrictComInterfaceByAggregation(IntPtr outerObject, bool queryForType = true)
110113
{
111114
if (queryForType)
@@ -391,23 +394,23 @@ public void Document(StringLineBuilder output)
391394
/// A base class for exposing an enumerable collection through an index based accessor
392395
/// </summary>
393396
/// <typeparam name="TItem">the collection element type</typeparam>
394-
public class IIndexedCollection<TItem> : IEnumerable<TItem>
397+
public abstract class IIndexedCollectionBase<TItem> : IEnumerable<TItem>
395398
where TItem : class
396399
{
397-
IEnumerator IEnumerable.GetEnumerator() => new IIndexedCollectionEnumerator<IIndexedCollection<TItem>, TItem>(this);
398-
public IEnumerator<TItem> GetEnumerator() => new IIndexedCollectionEnumerator<IIndexedCollection<TItem>, TItem>(this);
400+
IEnumerator IEnumerable.GetEnumerator() => new IIndexedCollectionEnumerator<IIndexedCollectionBase<TItem>, TItem>(this);
401+
public IEnumerator<TItem> GetEnumerator() => new IIndexedCollectionEnumerator<IIndexedCollectionBase<TItem>, TItem>(this);
399402

400-
virtual public int Count { get => throw new NotImplementedException(); }
401-
virtual public TItem GetItemByIndex(int index) => throw new NotImplementedException();
403+
abstract public int Count { get; }
404+
abstract public TItem GetItemByIndex(int index);
402405
}
403406

404407
/// <summary>
405-
/// The enumerator implementation for IIndexedCollection
408+
/// The enumerator implementation for IIndexedCollectionBase
406409
/// </summary>
407-
/// <typeparam name="TCollection">the IIndexedCollection<> type</typeparam>
410+
/// <typeparam name="TCollection">the IIndexedCollectionBase<> type</typeparam>
408411
/// <typeparam name="TItem">the collection element type</typeparam>
409-
public class IIndexedCollectionEnumerator<TCollection, TItem> : IEnumerator<TItem>, IDisposable
410-
where TCollection : IIndexedCollection<TItem>
412+
public class IIndexedCollectionEnumerator<TCollection, TItem> : IEnumerator<TItem>
413+
where TCollection : IIndexedCollectionBase<TItem>
411414
where TItem : class
412415
{
413416
private TCollection _collection;
@@ -545,7 +548,7 @@ public class TypeInfoWrapper : ComTypes.ITypeInfo, IDisposable
545548
/// <summary>
546549
/// Exposes an enumerable collection of functions provided by the ITypeInfo
547550
/// </summary>
548-
public class FuncsCollection : IIndexedCollection<TypeInfoFunc>
551+
public class FuncsCollection : IIndexedCollectionBase<TypeInfoFunc>
549552
{
550553
TypeInfoWrapper _parent;
551554
public FuncsCollection(TypeInfoWrapper parent) => _parent = parent;
@@ -566,7 +569,7 @@ public TypeInfoFunc Find(string name, TypeInfoFunc.PROCKIND procKind)
566569
/// <summary>
567570
/// Exposes an enumerable collection of variables/fields provided by the ITypeInfo
568571
/// </summary>
569-
public class VarsCollection : IIndexedCollection<TypeInfoVar>
572+
public class VarsCollection : IIndexedCollectionBase<TypeInfoVar>
570573
{
571574
TypeInfoWrapper _parent;
572575
public VarsCollection(TypeInfoWrapper parent) => _parent = parent;
@@ -578,7 +581,7 @@ public class VarsCollection : IIndexedCollection<TypeInfoVar>
578581
/// <summary>
579582
/// Exposes an enumerable collection of implemented interfaces provided by the ITypeInfo
580583
/// </summary>
581-
public class ImplementedInterfacesCollection : IIndexedCollection<TypeInfoWrapper>
584+
public class ImplementedInterfacesCollection : IIndexedCollectionBase<TypeInfoWrapper>
582585
{
583586
TypeInfoWrapper _parent;
584587
public ImplementedInterfacesCollection(TypeInfoWrapper parent) => _parent = parent;
@@ -757,9 +760,12 @@ public TypeInfoWrapper(ComTypes.ITypeInfo rawTypeInfo)
757760
public TypeInfoWrapper(IntPtr rawObjectPtr, int? parentUserFormUniqueId = null)
758761
{
759762
_rawObjectPtr = rawObjectPtr;
760-
763+
761764
// We have to restrict interface requests to VBE hosted ITypeInfos due to a bug in their implementation.
762765
// See TypeInfoWrapper class XML doc for details.
766+
767+
// queryForType is passed as false for ITypeInfo here, as rawObjectPtr is known to point to the ITypeInfo vtable
768+
// additionally allowing it to query for ITypeInfo gives a _different_, and more prohibitive implementation of ITypeInfo
763769
_ITypeInfo_Aggregator = new RestrictComInterfaceByAggregation<ComTypes.ITypeInfo>(rawObjectPtr, queryForType: false);
764770
_IVBEComponent_Aggregator = new RestrictComInterfaceByAggregation<IVBEComponent>(rawObjectPtr);
765771
_IVBETypeInfo_Aggregator = new RestrictComInterfaceByAggregation<IVBETypeInfo>(rawObjectPtr);
@@ -808,7 +814,7 @@ TypeLibTextFields CachedTextFields
808814
public int HelpContext { get => CachedTextFields._helpContext; }
809815
public string HelpFile { get => CachedTextFields._helpFile; }
810816

811-
public string GetProgID() => (Container?.Name ?? "") + "." + CachedTextFields._name;
817+
public string GetProgID() => (Container?.Name ?? "{unnamedlibrary}") + "." + CachedTextFields._name;
812818

813819
public Guid GUID { get => Attributes.guid; }
814820
public TYPEKIND_VBE TypeKind { get => (TYPEKIND_VBE)Attributes.typekind; }
@@ -928,7 +934,7 @@ public object StdModExecute(string name, object[] args = null)
928934
/// Gets the control ITypeInfo by looking for the corresponding getter on the form interface and returning its retval type
929935
/// </summary>
930936
/// <param name="controlName">the name of the control</param>
931-
/// <returns>TypeInfoWrapper representing the type of control</returns>
937+
/// <returns>TypeInfoWrapper representing the type of control, typically the coclass, but this is host dependent</returns>
932938
public TypeInfoWrapper GetControlType(string controlName)
933939
{
934940
// TODO should encapsulate handling of raw datatypes
@@ -1140,7 +1146,7 @@ public class TypeLibWrapper : ComTypes.ITypeLib, IDisposable
11401146
/// <summary>
11411147
/// Exposes an enumerable collection of TypeInfo objects exposed by this ITypeLib
11421148
/// </summary>
1143-
public class TypeInfosCollection : IIndexedCollection<TypeInfoWrapper>
1149+
public class TypeInfosCollection : IIndexedCollectionBase<TypeInfoWrapper>
11441150
{
11451151
TypeLibWrapper _parent;
11461152
public TypeInfosCollection(TypeLibWrapper parent) => _parent = parent;
@@ -1172,7 +1178,7 @@ public TypeInfoWrapper Get(string searchTypeName)
11721178
/// <summary>
11731179
/// Exposes an enumerable collection of references used by the VBE type library
11741180
/// </summary>
1175-
public class ReferencesCollection : IIndexedCollection<TypeInfoReference>
1181+
public class ReferencesCollection : IIndexedCollectionBase<TypeInfoReference>
11761182
{
11771183
TypeLibWrapper _parent;
11781184
public ReferencesCollection(TypeLibWrapper parent) => _parent = parent;

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibsAPI.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public static bool DoesClassImplementInterface(TypeInfoWrapper classTypeInfo, st
516516
/// <param name="projectName">VBA Project name, as declared in the VBE</param>
517517
/// <param name="className">Document class name, as declared in the VBA project</param>
518518
/// <param name="interfaceProgIDs">An array of interface names, preceeded by the library container name, e.g. "Excel._Worksheet"</param>
519-
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched</param>
519+
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched, or -1 if no match</param>
520520
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
521521
public static bool DoesClassImplementInterface(IVBE ide, string projectName, string className, string[] interfaceProgIDs, out int matchedIndex)
522522
{
@@ -532,7 +532,7 @@ public static bool DoesClassImplementInterface(IVBE ide, string projectName, str
532532
/// <param name="project">Safe-com wrapper representing the VBE project</param>
533533
/// <param name="className">Document class name, as declared in the VBA project</param>
534534
/// <param name="interfaceProgIDs">An array of interface names, preceeded by the library container name, e.g. "Excel._Worksheet"</param>
535-
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched</param>
535+
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched, or -1 if no match</param>
536536
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
537537
public static bool DoesClassImplementInterface(IVBProject project, string className, string[] interfaceProgIDs, out int matchedIndex)
538538
{
@@ -548,7 +548,7 @@ public static bool DoesClassImplementInterface(IVBProject project, string classN
548548
/// <param name="projectTypeLib">Low-level ITypeLib wrapper representing the VBA project</param>
549549
/// <param name="className">Document class name, as declared in the VBA project</param>
550550
/// <param name="interfaceProgIDs">An array of interface names, preceeded by the library container name, e.g. "Excel._Worksheet"</param>
551-
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched</param>
551+
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched, or -1 if no match</param>
552552
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
553553
public static bool DoesClassImplementInterface(TypeLibWrapper projectTypeLib, string className, string[] interfaceProgIDs, out int matchedIndex)
554554
{
@@ -560,7 +560,7 @@ public static bool DoesClassImplementInterface(TypeLibWrapper projectTypeLib, st
560560
/// </summary>
561561
/// <param name="component">Safe-com wrapper representing the VBA component</param>
562562
/// <param name="interfaceProgIDs">An array of interface names, preceeded by the library container name, e.g. "Excel._Worksheet"</param>
563-
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched</param>
563+
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched, or -1 if no match</param>
564564
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
565565
public static bool DoesClassImplementInterface(IVBComponent component, string[] interfaceProgIDs, out int matchedIndex)
566566
{
@@ -572,7 +572,7 @@ public static bool DoesClassImplementInterface(IVBComponent component, string[]
572572
/// </summary>
573573
/// <param name="classTypeInfo">Low-level ITypeInfo wrapper representing the VBA project</param>
574574
/// <param name="interfaceProgIDs">An array of interface names, preceeded by the library container name, e.g. "Excel._Worksheet"</param>
575-
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched</param>
575+
/// <param name="matchedIndex">on return indicates the index into interfaceProgIDs that matched, or -1 if no match</param>
576576
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
577577
public static bool DoesClassImplementInterface(TypeInfoWrapper classTypeInfo, string[] interfaceProgIDs, out int matchedIndex)
578578
{
@@ -651,7 +651,7 @@ public static bool DoesClassImplementInterface(TypeInfoWrapper classTypeInfo, Gu
651651
/// <param name="projectName">VBA Project name, as declared in the VBE</param>
652652
/// <param name="className">Document class name, as declared in the VBA project</param>
653653
/// <param name="interfaceIIDs">An array of interface IIDs to check against</param>
654-
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched</param>
654+
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched, or -1 if no match</param>
655655
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
656656
public static bool DoesClassImplementInterface(IVBE ide, string projectName, string className, Guid[] interfaceIIDs, out int matchedIndex)
657657
{
@@ -667,7 +667,7 @@ public static bool DoesClassImplementInterface(IVBE ide, string projectName, str
667667
/// <param name="project">Safe-com wrapper representing the VBA project</param>
668668
/// <param name="className">Document class name, as declared in the VBA project</param>
669669
/// <param name="interfaceIIDs">An array of interface IIDs to check against</param>
670-
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched</param>
670+
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched, or -1 if no match</param>
671671
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
672672
public static bool DoesClassImplementInterface(IVBProject project, string className, Guid[] interfaceIIDs, out int matchedIndex)
673673
{
@@ -683,7 +683,7 @@ public static bool DoesClassImplementInterface(IVBProject project, string classN
683683
/// <param name="projectTypeLib">Low-level ITypeLib wrapper representing the VBA project</param>
684684
/// <param name="className">Document class name, as declared in the VBA project</param>
685685
/// <param name="interfaceIIDs">An array of interface IIDs to check against</param>
686-
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched</param>
686+
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched, or -1 if no match</param>
687687
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
688688
public static bool DoesClassImplementInterface(TypeLibWrapper projectTypeLib, string className, Guid[] interfaceIIDs, out int matchedIndex)
689689
{
@@ -695,7 +695,7 @@ public static bool DoesClassImplementInterface(TypeLibWrapper projectTypeLib, st
695695
/// </summary>
696696
/// <param name="component">Safe-com wrapper representing the VBA component</param>
697697
/// <param name="interfaceIIDs">An array of interface IIDs to check against</param>
698-
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched</param>
698+
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched, or -1 if no match</param>
699699
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
700700
public static bool DoesClassImplementInterface(IVBComponent component, Guid[] interfaceIIDs, out int matchedIndex)
701701
{
@@ -707,7 +707,7 @@ public static bool DoesClassImplementInterface(IVBComponent component, Guid[] in
707707
/// </summary>
708708
/// <param name="classTypeInfo">Low-level ITypeInfo wrapper representing the VBA project</param>
709709
/// <param name="interfaceIIDs">An array of interface IIDs to check against</param>
710-
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched</param>
710+
/// <param name="matchedIndex">on return indicates the index into interfaceIIDs that matched, or -1 if no match</param>
711711
/// <returns>bool indicating whether the class does inherit one of the specified interfaces</returns>
712712
public static bool DoesClassImplementInterface(TypeInfoWrapper classTypeInfo, Guid[] interfaceIIDs, out int matchedIndex)
713713
{
@@ -843,14 +843,14 @@ public static string GetDocumentClassControlType(TypeInfoWrapper documentClass,
843843
{
844844
return documentClass.GetSafeImplementedTypeInfo(0).GetControlType(controlName).GetProgID();
845845
}
846-
846+
847847
/// <summary>
848848
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
849849
/// </summary>
850850
/// <param name="ide">Safe-com wrapper representing the VBE</param>
851851
/// <param name="projectName">The VBA project name</param>
852852
/// <param name="componentName">The name of the component (module/class etc) to get flags for</param>
853-
/// <returns>bool indicating success/failure.</returns>
853+
/// <returns>ComTypes.TYPEFLAGS flags from the ITypeInfo</returns>
854854
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBE ide, string projectName, string componentName)
855855
{
856856
using (var typeLibs = new VBETypeLibsAccessor(ide))
@@ -864,7 +864,7 @@ public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBE ide, string projectN
864864
/// </summary>
865865
/// <param name="project">Safe-com wrapper representing the VBA project</param>
866866
/// <param name="componentName">The name of the component (module/class etc) to get flags for</param>
867-
/// <returns>bool indicating success/failure.</returns>
867+
/// <returns>ComTypes.TYPEFLAGS flags from the ITypeInfo</returns>
868868
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBProject project, string componentName)
869869
{
870870
using (var typeLib = TypeLibWrapper.FromVBProject(project))
@@ -878,7 +878,7 @@ public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBProject project, strin
878878
/// </summary>
879879
/// <param name="projectTypeLib">Low-level ITypeLib wrapper representing the VBA project</param>
880880
/// <param name="componentName">The name of the component (module/class etc) to get flags for</param>
881-
/// <returns>bool indicating success/failure.</returns>
881+
/// <returns>ComTypes.TYPEFLAGS flags from the ITypeInfo</returns>
882882
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(TypeLibWrapper projectTypeLib, string componentName)
883883
{
884884
return GetComponentTypeFlags(projectTypeLib.TypeInfos.Get(componentName));
@@ -888,7 +888,7 @@ public static ComTypes.TYPEFLAGS GetComponentTypeFlags(TypeLibWrapper projectTyp
888888
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
889889
/// </summary>
890890
/// <param name="component">Safe-com wrapper representing the VBA component to get flags for</param>
891-
/// <returns>bool indicating success/failure.</returns>
891+
/// <returns>ComTypes.TYPEFLAGS flags from the ITypeInfo</returns>
892892
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBComponent component)
893893
{
894894
return GetComponentTypeFlags(component.ParentProject, component.Name);
@@ -898,7 +898,7 @@ public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBComponent component)
898898
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
899899
/// </summary>
900900
/// <param name="componentTypeInfo">Low-level ITypeInfo wrapper representing the VBA component to get flags for</param>
901-
/// <returns>bool indicating success/failure.</returns>
901+
/// <returns>ComTypes.TYPEFLAGS flags from the ITypeInfo</returns>
902902
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(TypeInfoWrapper componentTypeInfo)
903903
{
904904
return componentTypeInfo.Flags;

0 commit comments

Comments
 (0)