-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathComTypeName.cs
59 lines (50 loc) · 1.72 KB
/
ComTypeName.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Linq;
using System.Runtime.Serialization;
namespace Rubberduck.Parsing.ComReflection
{
[DataContract]
[KnownType(typeof(ComProject))]
public class ComTypeName
{
[DataMember(IsRequired = true)]
public Guid EnumGuid { get; private set; } = Guid.Empty;
public bool IsEnumMember => !EnumGuid.Equals(Guid.Empty);
[DataMember(IsRequired = true)]
public Guid AliasGuid { get; private set; } = Guid.Empty;
public bool IsAliased => !AliasGuid.Equals(Guid.Empty);
public ComProject Project { get; set; }
[DataMember(IsRequired = true)]
private string _rawName;
public string Name
{
get
{
if (IsEnumMember && ComProject.KnownEnumerations.TryGetValue(EnumGuid, out var enumeration))
{
return enumeration.Name;
}
if (IsAliased && ComProject.KnownAliases.TryGetValue(AliasGuid, out var alias))
{
return alias.Name;
}
if (Project == null)
{
return _rawName;
}
var softAlias = Project.Aliases.FirstOrDefault(x => x.Name.Equals(_rawName));
return softAlias == null ? _rawName : softAlias.TypeName;
}
}
public ComTypeName(ComProject project, string name)
{
Project = project;
_rawName = name;
}
public ComTypeName(ComProject project, string name, Guid enumGuid, Guid aliasGuid) : this(project, name)
{
EnumGuid = enumGuid;
AliasGuid = aliasGuid;
}
}
}