Skip to content

Commit 222198a

Browse files
authored
Merge pull request #2771 from comintern/next
Make retrieval of TypeName safe with 64 bit typelibs.
2 parents 5f9658c + 225a809 commit 222198a

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Diagnostics;
3-
using System.Runtime.InteropServices;
1+
using System.Diagnostics;
42
using System.Runtime.InteropServices.ComTypes;
53
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
64
using TYPEFLAGS = System.Runtime.InteropServices.ComTypes.TYPEFLAGS;
@@ -10,7 +8,6 @@ namespace Rubberduck.Parsing.ComReflection
108
[DebuggerDisplay("{Name} As {TypeName}")]
119
public class ComAlias : ComBase
1210
{
13-
public VarEnum VarType { get; private set; }
1411
public string TypeName { get; private set; }
1512
public bool IsHidden { get; private set; }
1613
public bool IsRestricted { get; private set; }
@@ -20,7 +17,6 @@ public ComAlias(ITypeLib typeLib, ITypeInfo info, int index, TYPEATTR attributes
2017
Index = index;
2118
Documentation = new ComDocumentation(typeLib, index);
2219
Guid = attributes.guid;
23-
VarType = (VarEnum)attributes.tdescAlias.vt;
2420
IsHidden = attributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FHIDDEN);
2521
IsRestricted = attributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FRESTRICTED);
2622

@@ -29,22 +25,9 @@ public ComAlias(ITypeLib typeLib, ITypeInfo info, int index, TYPEATTR attributes
2925
TypeName = "LongPtr";
3026
return;
3127
}
32-
33-
if (ComVariant.TypeNames.ContainsKey(VarType))
34-
{
35-
TypeName = ComVariant.TypeNames[VarType];
36-
}
37-
else if (VarType == VarEnum.VT_USERDEFINED)
38-
{
39-
ITypeInfo refType;
40-
info.GetRefTypeInfo((int)attributes.tdescAlias.lpValue, out refType);
41-
var doc = new ComDocumentation(refType, -1);
42-
TypeName = doc.Name;
43-
}
44-
else
45-
{
46-
throw new NotImplementedException(string.Format("Didn't expect an alias with a type of {0}.", VarType));
47-
}
28+
29+
var aliased = new ComParameter(attributes, info);
30+
TypeName = aliased.TypeName;
4831
}
4932
}
5033
}

Rubberduck.Parsing/ComReflection/ComParameter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public string DeclarationName
3737
public bool IsOptional { get; private set; }
3838
public bool IsParamArray { get; set; }
3939

40-
4140
private Guid _enumGuid = Guid.Empty;
4241
public bool IsEnumMember
4342
{
@@ -81,6 +80,12 @@ public ComParameter(ELEMDESC elemDesc, ITypeInfo info, string name)
8180
DefaultAsEnum = member != null ? member.Name : string.Empty;
8281
}
8382

83+
//This overload should only be used for retrieving the TypeName from a random TYPEATTR. TODO: Should be a base class of ComParameter instead.
84+
public ComParameter(TYPEATTR attributes, ITypeInfo info)
85+
{
86+
GetParameterType(attributes.tdescAlias, info);
87+
}
88+
8489
private void GetParameterType(TYPEDESC desc, ITypeInfo info)
8590
{
8691
var vt = (VarEnum)desc.vt;

0 commit comments

Comments
 (0)