1
- using System ;
1
+ #if DEBUG && TRACE_TYPEAPI
2
+ using System ;
2
3
using System . Runtime . CompilerServices ;
3
4
using System . Runtime . InteropServices . ComTypes ;
4
5
using Rubberduck . VBEditor . ComManagement . TypeLibs . Abstract ;
5
6
using Rubberduck . VBEditor . ComManagement . TypeLibs . Unmanaged ;
6
7
7
8
namespace Rubberduck . VBEditor . ComManagement . TypeLibs . DebugInternal
8
9
{
10
+ /// <summary>
11
+ /// Wraps the existing implementation so that we can trace the calls for
12
+ /// diagnostics or debugging. See <see cref="TypeApiFactory"/> for
13
+ /// creating a class to be traced. The class should not be created directly.
14
+ /// </summary>
9
15
internal class TypeLibWrapperTracer : ITypeLibWrapper , ITypeLibInternal
10
16
{
11
17
private readonly ITypeLibWrapper _wrapper ;
@@ -27,119 +33,129 @@ private static void After(string parameters = null, [CallerMemberName] string me
27
33
System . Diagnostics . Debug . Print ( $ "Leaving { nameof ( ITypeLibWrapper ) } ::{ methodName } ; { parameters } ") ;
28
34
}
29
35
30
- public int GetTypeInfoCount ( )
36
+ private int GetTypeInfoCount ( )
31
37
{
32
38
Before ( ) ;
33
39
var result = _wrapper . GetTypeInfoCount ( ) ;
34
40
After ( $ "{ nameof ( result ) } : { result } ") ;
35
41
return result ;
36
42
}
37
43
38
- public int GetTypeInfo ( int index , IntPtr ppTI )
44
+ int ITypeLibInternal . GetTypeInfoCount ( )
45
+ {
46
+ return GetTypeInfoCount ( ) ;
47
+ }
48
+
49
+ int ITypeLib . GetTypeInfoCount ( )
50
+ {
51
+ return GetTypeInfoCount ( ) ;
52
+ }
53
+
54
+ int ITypeLibInternal . GetTypeInfo ( int index , IntPtr ppTI )
39
55
{
40
56
Before ( $ "{ nameof ( index ) } : { index } , { nameof ( ppTI ) } : { ppTI } ") ;
41
57
var result = _inner . GetTypeInfo ( index , ppTI ) ;
42
58
After ( $ "{ nameof ( result ) } : { result } , { nameof ( ppTI ) } : { ppTI } ") ;
43
59
return result ;
44
60
}
45
61
46
- public int GetTypeInfoType ( int index , IntPtr pTKind )
62
+ int ITypeLibInternal . GetTypeInfoType ( int index , IntPtr pTKind )
47
63
{
48
64
Before ( $ "{ nameof ( index ) } : { index } , { nameof ( pTKind ) } : { pTKind } ") ;
49
65
var result = _inner . GetTypeInfoType ( index , pTKind ) ;
50
66
After ( $ "{ nameof ( result ) } : { result } , { nameof ( pTKind ) } : { pTKind } ") ;
51
67
return result ;
52
68
}
53
69
54
- public int GetTypeInfoOfGuid ( ref Guid guid , IntPtr ppTInfo )
70
+ int ITypeLibInternal . GetTypeInfoOfGuid ( ref Guid guid , IntPtr ppTInfo )
55
71
{
56
72
Before ( $ "{ nameof ( guid ) } : { guid } , { nameof ( ppTInfo ) } : { ppTInfo } ") ;
57
73
var result = _inner . GetTypeInfoOfGuid ( ref guid , ppTInfo ) ;
58
74
After ( $ "{ nameof ( result ) } : { result } , { nameof ( ppTInfo ) } : { ppTInfo } ") ;
59
75
return result ;
60
76
}
61
77
62
- public int GetLibAttr ( IntPtr ppTLibAttr )
78
+ int ITypeLibInternal . GetLibAttr ( IntPtr ppTLibAttr )
63
79
{
64
80
Before ( $ "{ nameof ( ppTLibAttr ) } : { ppTLibAttr } ") ;
65
81
var result = _inner . GetLibAttr ( ppTLibAttr ) ;
66
82
After ( $ "{ nameof ( result ) } : { result } , { nameof ( ppTLibAttr ) } : { ppTLibAttr } ") ;
67
83
return result ;
68
84
}
69
85
70
- public int GetTypeComp ( IntPtr ppTComp )
86
+ int ITypeLibInternal . GetTypeComp ( IntPtr ppTComp )
71
87
{
72
88
Before ( $ "{ nameof ( ppTComp ) } : { ppTComp } ") ;
73
89
var result = _inner . GetTypeComp ( ppTComp ) ;
74
90
After ( $ "{ nameof ( result ) } : { result } , { nameof ( ppTComp ) } : { ppTComp } ") ;
75
91
return result ;
76
92
}
77
93
78
- public int GetDocumentation ( int index , IntPtr strName , IntPtr strDocString , IntPtr dwHelpContext , IntPtr strHelpFile )
94
+ int ITypeLibInternal . GetDocumentation ( int index , IntPtr strName , IntPtr strDocString , IntPtr dwHelpContext , IntPtr strHelpFile )
79
95
{
80
96
Before ( $ "{ nameof ( index ) } : { index } , { nameof ( strName ) } : { strName } , { nameof ( strDocString ) } : { strDocString } , { nameof ( dwHelpContext ) } : { dwHelpContext } , { nameof ( strHelpFile ) } : { strHelpFile } ") ;
81
97
var result = _inner . GetDocumentation ( index , strName , strDocString , dwHelpContext , strHelpFile ) ;
82
98
After ( $ "{ nameof ( result ) } : { result } , { nameof ( strName ) } : { strName } , { nameof ( strDocString ) } : { strDocString } , { nameof ( dwHelpContext ) } : { dwHelpContext } , { nameof ( strHelpFile ) } : { strHelpFile } ") ;
83
99
return result ;
84
100
}
85
101
86
- public int IsName ( string szNameBuf , int lHashVal , IntPtr pfName )
102
+ int ITypeLibInternal . IsName ( string szNameBuf , int lHashVal , IntPtr pfName )
87
103
{
88
104
Before ( $ "{ nameof ( szNameBuf ) } : { szNameBuf } , { nameof ( lHashVal ) } : { lHashVal } , { nameof ( pfName ) } : { pfName } ") ;
89
105
var result = _inner . IsName ( szNameBuf , lHashVal , pfName ) ;
90
106
After ( $ "{ nameof ( result ) } : { result } , { nameof ( pfName ) } : { pfName } ") ;
91
107
return result ;
92
108
}
93
109
94
- public int FindName ( string szNameBuf , int lHashVal , IntPtr ppTInfo , IntPtr rgMemId , IntPtr pcFound )
110
+ int ITypeLibInternal . FindName ( string szNameBuf , int lHashVal , IntPtr ppTInfo , IntPtr rgMemId , IntPtr pcFound )
95
111
{
96
112
Before ( $ "{ nameof ( szNameBuf ) } : { szNameBuf } , { nameof ( lHashVal ) } : { lHashVal } , { nameof ( ppTInfo ) } : { ppTInfo } , { nameof ( rgMemId ) } : { rgMemId } , { nameof ( pcFound ) } : { pcFound } ") ;
97
113
var result = _inner . FindName ( szNameBuf , lHashVal , ppTInfo , rgMemId , pcFound ) ;
98
114
After ( $ "{ nameof ( result ) } : { result } , { nameof ( ppTInfo ) } : { ppTInfo } , { nameof ( rgMemId ) } : { rgMemId } , { nameof ( pcFound ) } : { pcFound } ") ;
99
115
return result ;
100
116
}
101
117
102
- public void GetTypeInfo ( int index , out ITypeInfo ppTI )
118
+ void ITypeLib . GetTypeInfo ( int index , out ITypeInfo ppTI )
103
119
{
104
120
Before ( $ "{ nameof ( index ) } : { index } ") ;
105
121
_wrapper . GetTypeInfo ( index , out var t ) ;
106
122
After ( $ "{ nameof ( ppTI ) } : { t ? . GetHashCode ( ) } ") ;
107
123
ppTI = t ;
108
124
}
109
125
110
- public void GetTypeInfoType ( int index , out TYPEKIND pTKind )
126
+ void ITypeLib . GetTypeInfoType ( int index , out TYPEKIND pTKind )
111
127
{
112
128
Before ( $ "{ nameof ( index ) } : { index } ") ;
113
129
_wrapper . GetTypeInfoType ( index , out var t ) ;
114
130
After ( $ "{ nameof ( pTKind ) } : { t } ") ;
115
131
pTKind = t ;
116
132
}
117
133
118
- public void GetTypeInfoOfGuid ( ref Guid guid , out ITypeInfo ppTInfo )
134
+ void ITypeLib . GetTypeInfoOfGuid ( ref Guid guid , out ITypeInfo ppTInfo )
119
135
{
120
136
Before ( $ "{ nameof ( guid ) } : { guid } ") ;
121
137
_wrapper . GetTypeInfoOfGuid ( ref guid , out var t ) ;
122
138
After ( $ "{ nameof ( ppTInfo ) } : { t ? . GetHashCode ( ) } ") ;
123
139
ppTInfo = t ;
124
140
}
125
141
126
- public void GetLibAttr ( out IntPtr ppTLibAttr )
142
+ void ITypeLib . GetLibAttr ( out IntPtr ppTLibAttr )
127
143
{
128
144
Before ( ) ;
129
145
_wrapper . GetLibAttr ( out var t ) ;
130
146
After ( $ "{ nameof ( ppTLibAttr ) } : { t } ") ;
131
147
ppTLibAttr = t ;
132
148
}
133
149
134
- public void GetTypeComp ( out ITypeComp ppTComp )
150
+ void ITypeLib . GetTypeComp ( out ITypeComp ppTComp )
135
151
{
136
152
Before ( ) ;
137
153
_wrapper . GetTypeComp ( out var t ) ;
138
154
After ( $ "{ nameof ( ppTComp ) } : { t ? . GetHashCode ( ) } ") ;
139
155
ppTComp = t ;
140
156
}
141
157
142
- public void GetDocumentation ( int index , out string strName , out string strDocString , out int dwHelpContext ,
158
+ void ITypeLib . GetDocumentation ( int index , out string strName , out string strDocString , out int dwHelpContext ,
143
159
out string strHelpFile )
144
160
{
145
161
Before ( $ "{ nameof ( index ) } : { index } ") ;
@@ -151,36 +167,46 @@ public void GetDocumentation(int index, out string strName, out string strDocStr
151
167
strHelpFile = t4 ;
152
168
}
153
169
154
- public bool IsName ( string szNameBuf , int lHashVal )
170
+ bool ITypeLib . IsName ( string szNameBuf , int lHashVal )
155
171
{
156
172
Before ( $ "{ nameof ( szNameBuf ) } : { szNameBuf } , { nameof ( lHashVal ) } : { lHashVal } ") ;
157
173
var result = _wrapper . IsName ( szNameBuf , lHashVal ) ;
158
174
After ( $ "{ nameof ( result ) } : { result } ") ;
159
175
return result ;
160
176
}
161
177
162
- public void FindName ( string szNameBuf , int lHashVal , ITypeInfo [ ] ppTInfo , int [ ] rgMemId , ref short pcFound )
178
+ void ITypeLib . FindName ( string szNameBuf , int lHashVal , ITypeInfo [ ] ppTInfo , int [ ] rgMemId , ref short pcFound )
163
179
{
164
180
Before ( $ "{ nameof ( szNameBuf ) } : { szNameBuf } , { nameof ( lHashVal ) } : { lHashVal } , { ppTInfo } : { ( ppTInfo == null ? "null" : "objects" ) } , { nameof ( rgMemId ) } : { ( rgMemId == null ? "null" : "ints" ) } , { nameof ( pcFound ) } : { pcFound } ") ;
165
181
_wrapper . FindName ( szNameBuf , lHashVal , ppTInfo , rgMemId , ref pcFound ) ;
166
182
After ( $ "{ ppTInfo } : { ( ppTInfo == null ? "null" : "objects" ) } , { nameof ( rgMemId ) } : { ( rgMemId == null ? "null" : "ints" ) } , { nameof ( pcFound ) } : { pcFound } ") ;
167
183
}
168
184
169
- public void ReleaseTLibAttr ( IntPtr pTLibAttr )
185
+ private void ReleaseTLibAttr ( IntPtr pTLibAttr )
170
186
{
171
187
Before ( $ "{ nameof ( pTLibAttr ) } : { pTLibAttr } ") ;
172
188
_wrapper . ReleaseTLibAttr ( pTLibAttr ) ;
173
189
After ( ) ;
174
190
}
175
191
192
+ void ITypeLibInternal . ReleaseTLibAttr ( IntPtr pTLibAttr )
193
+ {
194
+ ReleaseTLibAttr ( pTLibAttr ) ;
195
+ }
196
+
197
+ void ITypeLib . ReleaseTLibAttr ( IntPtr pTLibAttr )
198
+ {
199
+ ReleaseTLibAttr ( pTLibAttr ) ;
200
+ }
201
+
176
202
public void Dispose ( )
177
203
{
178
204
Before ( ) ;
179
205
_wrapper . Dispose ( ) ;
180
206
After ( ) ;
181
207
}
182
208
183
- public string Name
209
+ string ITypeLibWrapper . Name
184
210
{
185
211
get
186
212
{
@@ -191,7 +217,7 @@ public string Name
191
217
}
192
218
}
193
219
194
- public string DocString
220
+ string ITypeLibWrapper . DocString
195
221
{
196
222
get
197
223
{
@@ -202,7 +228,7 @@ public string DocString
202
228
}
203
229
}
204
230
205
- public int HelpContext
231
+ int ITypeLibWrapper . HelpContext
206
232
{
207
233
get
208
234
{
@@ -213,7 +239,7 @@ public int HelpContext
213
239
}
214
240
}
215
241
216
- public string HelpFile
242
+ string ITypeLibWrapper . HelpFile
217
243
{
218
244
get
219
245
{
@@ -224,7 +250,7 @@ public string HelpFile
224
250
}
225
251
}
226
252
227
- public bool HasVBEExtensions
253
+ bool ITypeLibWrapper . HasVBEExtensions
228
254
{
229
255
get
230
256
{
@@ -235,7 +261,7 @@ public bool HasVBEExtensions
235
261
}
236
262
}
237
263
238
- public int TypesCount
264
+ int ITypeLibWrapper . TypesCount
239
265
{
240
266
get
241
267
{
@@ -246,7 +272,7 @@ public int TypesCount
246
272
}
247
273
}
248
274
249
- public ITypeInfoWrapperCollection TypeInfos
275
+ ITypeInfoWrapperCollection ITypeLibWrapper . TypeInfos
250
276
{
251
277
get
252
278
{
@@ -257,7 +283,7 @@ public ITypeInfoWrapperCollection TypeInfos
257
283
}
258
284
}
259
285
260
- public ITypeLibVBEExtensions VBEExtensions
286
+ ITypeLibVBEExtensions ITypeLibWrapper . VBEExtensions
261
287
{
262
288
get
263
289
{
@@ -268,7 +294,7 @@ public ITypeLibVBEExtensions VBEExtensions
268
294
}
269
295
}
270
296
271
- public TYPELIBATTR Attributes
297
+ TYPELIBATTR ITypeLibWrapper . Attributes
272
298
{
273
299
get
274
300
{
@@ -279,7 +305,7 @@ public TYPELIBATTR Attributes
279
305
}
280
306
}
281
307
282
- public int GetSafeTypeInfoByIndex ( int index , out ITypeInfoWrapper outTI )
308
+ int ITypeLibWrapper . GetSafeTypeInfoByIndex ( int index , out ITypeInfoWrapper outTI )
283
309
{
284
310
Before ( $ "{ nameof ( index ) } : { index } ") ;
285
311
var result = _wrapper . GetSafeTypeInfoByIndex ( index , out var t ) ;
@@ -289,3 +315,4 @@ public int GetSafeTypeInfoByIndex(int index, out ITypeInfoWrapper outTI)
289
315
}
290
316
}
291
317
}
318
+ #endif
0 commit comments