1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 namespace System.Reflection.Metadata.Ecma335
6 {
7     public static class CodedIndex
8     {
9         /// <summary>
10         /// Calculates a HasCustomAttribute coded index for the specified handle.
11         /// </summary>
12         /// <param name="handle">
13         /// <see cref="MethodDefinitionHandle"/>,
14         /// <see cref="FieldDefinitionHandle"/>,
15         /// <see cref="TypeReferenceHandle"/>,
16         /// <see cref="TypeDefinitionHandle"/>,
17         /// <see cref="ParameterHandle"/>,
18         /// <see cref="InterfaceImplementationHandle"/>,
19         /// <see cref="MemberReferenceHandle"/>,
20         /// <see cref="ModuleDefinitionHandle"/>,
21         /// <see cref="DeclarativeSecurityAttributeHandle"/>,
22         /// <see cref="PropertyDefinitionHandle"/>,
23         /// <see cref="EventDefinitionHandle"/>,
24         /// <see cref="StandaloneSignatureHandle"/>,
25         /// <see cref="ModuleReferenceHandle"/>,
26         /// <see cref="TypeSpecificationHandle"/>,
27         /// <see cref="AssemblyDefinitionHandle"/>,
28         /// <see cref="AssemblyReferenceHandle"/>,
29         /// <see cref="AssemblyFileHandle"/>,
30         /// <see cref="ExportedTypeHandle"/>,
31         /// <see cref="ManifestResourceHandle"/>,
32         /// <see cref="GenericParameterHandle"/>,
33         /// <see cref="GenericParameterConstraintHandle"/> or
34         /// <see cref="MethodSpecificationHandle"/>.
35         /// </param>
36         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
37         public static int HasCustomAttribute(EntityHandle handle) => (handle.RowId << (int)HasCustomAttributeTag.BitCount) | (int)ToHasCustomAttributeTag(handle.Kind);
38 
39         /// <summary>
40         /// Calculates a HasConstant coded index for the specified handle.
41         /// </summary>
42         /// <param name="handle"><see cref="ParameterHandle"/>, <see cref="FieldDefinitionHandle"/>, or <see cref="PropertyDefinitionHandle"/></param>
43         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
44         public static int HasConstant(EntityHandle handle) => (handle.RowId << (int)HasConstantTag.BitCount) | (int)ToHasConstantTag(handle.Kind);
45 
46         /// <summary>
47         /// Calculates a CustomAttributeType coded index for the specified handle.
48         /// </summary>
49         /// <param name="handle"><see cref="MethodDefinitionHandle"/> or <see cref="MemberReferenceHandle"/></param>
50         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
51         public static int CustomAttributeType(EntityHandle handle) => (handle.RowId << (int)CustomAttributeTypeTag.BitCount) | (int)ToCustomAttributeTypeTag(handle.Kind);
52 
53         /// <summary>
54         /// Calculates a HasDeclSecurity coded index for the specified handle.
55         /// </summary>
56         /// <param name="handle"><see cref="TypeDefinitionHandle"/>, <see cref="MethodDefinitionHandle"/>, or <see cref="AssemblyDefinitionHandle"/></param>
57         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
58         public static int HasDeclSecurity(EntityHandle handle) => (handle.RowId << (int)HasDeclSecurityTag.BitCount) | (int)ToHasDeclSecurityTag(handle.Kind);
59 
60         /// <summary>
61         /// Calculates a HasFieldMarshal coded index for the specified handle.
62         /// </summary>
63         /// <param name="handle"><see cref = "ParameterHandle" /> or <see cref="FieldDefinitionHandle"/></param>
64         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
65         public static int HasFieldMarshal(EntityHandle handle) => (handle.RowId << (int)HasFieldMarshalTag.BitCount) | (int)ToHasFieldMarshalTag(handle.Kind);
66 
67         /// <summary>
68         /// Calculates a HasSemantics coded index for the specified handle.
69         /// </summary>
70         /// <param name="handle"><see cref="EventDefinitionHandle"/> or <see cref="PropertyDefinitionHandle"/></param>
71         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
72         public static int HasSemantics(EntityHandle handle) => (handle.RowId << (int)HasSemanticsTag.BitCount) | (int)ToHasSemanticsTag(handle.Kind);
73 
74         /// <summary>
75         /// Calculates a Implementation coded index for the specified handle.
76         /// </summary>
77         /// <param name="handle"><see cref="AssemblyFileHandle"/>, <see cref="ExportedTypeHandle"/> or <see cref="AssemblyReferenceHandle"/></param>
78         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
79         public static int Implementation(EntityHandle handle) => (handle.RowId << (int)ImplementationTag.BitCount) | (int)ToImplementationTag(handle.Kind);
80 
81         /// <summary>
82         /// Calculates a MemberForwarded coded index for the specified handle.
83         /// </summary>
84         /// <param name="handle"><see cref="FieldDefinition"/>, <see cref="MethodDefinition"/></param>
85         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
86         public static int MemberForwarded(EntityHandle handle) => (handle.RowId << (int)MemberForwardedTag.BitCount) | (int)ToMemberForwardedTag(handle.Kind);
87 
88         /// <summary>
89         /// Calculates a MemberRefParent coded index for the specified handle.
90         /// </summary>
91         /// <param name="handle">
92         /// <see cref="TypeDefinitionHandle"/>,
93         /// <see cref="TypeReferenceHandle"/>,
94         /// <see cref="ModuleReferenceHandle"/>,
95         /// <see cref="MethodDefinitionHandle"/>, or
96         /// <see cref="TypeSpecificationHandle"/>.
97         /// </param>
98         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
99         public static int MemberRefParent(EntityHandle handle) => (handle.RowId << (int)MemberRefParentTag.BitCount) | (int)ToMemberRefParentTag(handle.Kind);
100 
101         /// <summary>
102         /// Calculates a MethodDefOrRef coded index for the specified handle.
103         /// </summary>
104         /// <param name="handle"><see cref="MethodDefinitionHandle"/> or <see cref="MemberReferenceHandle"/></param>
105         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
106         public static int MethodDefOrRef(EntityHandle handle) => (handle.RowId << (int)MethodDefOrRefTag.BitCount) | (int)ToMethodDefOrRefTag(handle.Kind);
107 
108         /// <summary>
109         /// Calculates a ResolutionScope coded index for the specified handle.
110         /// </summary>
111         /// <param name="handle"><see cref="ModuleDefinitionHandle"/>, <see cref="ModuleReferenceHandle"/>, <see cref="AssemblyReferenceHandle"/> or <see cref="TypeReferenceHandle"/></param>
112         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
113         public static int ResolutionScope(EntityHandle handle) => (handle.RowId << (int)ResolutionScopeTag.BitCount) | (int)ToResolutionScopeTag(handle.Kind);
114 
115         /// <summary>
116         /// Calculates a TypeDefOrRef coded index for the specified handle.
117         /// </summary>
118         /// <param name="handle"><see cref="TypeDefinitionHandle"/> or <see cref="TypeReferenceHandle"/></param>
119         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
120         public static int TypeDefOrRef(EntityHandle handle) => (handle.RowId << (int)TypeDefOrRefTag.BitCount) | (int)ToTypeDefOrRefTag(handle.Kind);
121 
122         /// <summary>
123         /// Calculates a TypeDefOrRefOrSpec coded index for the specified handle.
124         /// </summary>
125         /// <param name="handle"><see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle"/> or <see cref="TypeSpecificationHandle"/></param>
126         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
127         public static int TypeDefOrRefOrSpec(EntityHandle handle) => (handle.RowId << (int)TypeDefOrRefOrSpecTag.BitCount) | (int)ToTypeDefOrRefOrSpecTag(handle.Kind);
128 
129         /// <summary>
130         /// Calculates a TypeOrMethodDef coded index for the specified handle.
131         /// </summary>
132         /// <param name="handle"><see cref="TypeDefinitionHandle"/> or <see cref="MethodDefinitionHandle"/></param>
133         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
134         public static int TypeOrMethodDef(EntityHandle handle) => (handle.RowId << (int)TypeOrMethodDefTag.BitCount) | (int)ToTypeOrMethodDefTag(handle.Kind);
135 
136         /// <summary>
137         /// Calculates a HasCustomDebugInformation coded index for the specified handle.
138         /// </summary>
139         /// <param name="handle">
140         /// <see cref="MethodDefinitionHandle"/>,
141         /// <see cref="FieldDefinitionHandle"/>,
142         /// <see cref="TypeReferenceHandle"/>,
143         /// <see cref="TypeDefinitionHandle"/>,
144         /// <see cref="ParameterHandle"/>,
145         /// <see cref="InterfaceImplementationHandle"/>,
146         /// <see cref="MemberReferenceHandle"/>,
147         /// <see cref="ModuleDefinitionHandle"/>,
148         /// <see cref="DeclarativeSecurityAttributeHandle"/>,
149         /// <see cref="PropertyDefinitionHandle"/>,
150         /// <see cref="EventDefinitionHandle"/>,
151         /// <see cref="StandaloneSignatureHandle"/>,
152         /// <see cref="ModuleReferenceHandle"/>,
153         /// <see cref="TypeSpecificationHandle"/>,
154         /// <see cref="AssemblyDefinitionHandle"/>,
155         /// <see cref="AssemblyReferenceHandle"/>,
156         /// <see cref="AssemblyFileHandle"/>,
157         /// <see cref="ExportedTypeHandle"/>,
158         /// <see cref="ManifestResourceHandle"/>,
159         /// <see cref="GenericParameterHandle"/>,
160         /// <see cref="GenericParameterConstraintHandle"/>,
161         /// <see cref="MethodSpecificationHandle"/>,
162         /// <see cref="DocumentHandle"/>,
163         /// <see cref="LocalScopeHandle"/>,
164         /// <see cref="LocalVariableHandle"/>,
165         /// <see cref="LocalConstantHandle"/> or
166         /// <see cref="ImportScopeHandle"/>.
167         /// </param>
168         /// <exception cref="ArgumentException">Unexpected handle kind.</exception>
169         public static int HasCustomDebugInformation(EntityHandle handle) => (handle.RowId << (int)HasCustomDebugInformationTag.BitCount) | (int)ToHasCustomDebugInformationTag(handle.Kind);
170 
171         private enum HasCustomAttributeTag
172         {
173             MethodDef = 0,
174             Field = 1,
175             TypeRef = 2,
176             TypeDef = 3,
177             Param = 4,
178             InterfaceImpl = 5,
179             MemberRef = 6,
180             Module = 7,
181             DeclSecurity = 8,
182             Property = 9,
183             Event = 10,
184             StandAloneSig = 11,
185             ModuleRef = 12,
186             TypeSpec = 13,
187             Assembly = 14,
188             AssemblyRef = 15,
189             File = 16,
190             ExportedType = 17,
191             ManifestResource = 18,
192             GenericParam = 19,
193             GenericParamConstraint = 20,
194             MethodSpec = 21,
195 
196             BitCount = 5
197         }
198 
ToHasCustomAttributeTag(HandleKind kind)199         private static HasCustomAttributeTag ToHasCustomAttributeTag(HandleKind kind)
200         {
201             switch (kind)
202             {
203                 case HandleKind.MethodDefinition: return HasCustomAttributeTag.MethodDef;
204                 case HandleKind.FieldDefinition: return HasCustomAttributeTag.Field;
205                 case HandleKind.TypeReference: return HasCustomAttributeTag.TypeRef;
206                 case HandleKind.TypeDefinition: return HasCustomAttributeTag.TypeDef;
207                 case HandleKind.Parameter: return HasCustomAttributeTag.Param;
208                 case HandleKind.InterfaceImplementation: return HasCustomAttributeTag.InterfaceImpl;
209                 case HandleKind.MemberReference: return HasCustomAttributeTag.MemberRef;
210                 case HandleKind.ModuleDefinition: return HasCustomAttributeTag.Module;
211                 case HandleKind.DeclarativeSecurityAttribute: return HasCustomAttributeTag.DeclSecurity;
212                 case HandleKind.PropertyDefinition: return HasCustomAttributeTag.Property;
213                 case HandleKind.EventDefinition: return HasCustomAttributeTag.Event;
214                 case HandleKind.StandaloneSignature: return HasCustomAttributeTag.StandAloneSig;
215                 case HandleKind.ModuleReference: return HasCustomAttributeTag.ModuleRef;
216                 case HandleKind.TypeSpecification: return HasCustomAttributeTag.TypeSpec;
217                 case HandleKind.AssemblyDefinition: return HasCustomAttributeTag.Assembly;
218                 case HandleKind.AssemblyReference: return HasCustomAttributeTag.AssemblyRef;
219                 case HandleKind.AssemblyFile: return HasCustomAttributeTag.File;
220                 case HandleKind.ExportedType: return HasCustomAttributeTag.ExportedType;
221                 case HandleKind.ManifestResource: return HasCustomAttributeTag.ManifestResource;
222                 case HandleKind.GenericParameter: return HasCustomAttributeTag.GenericParam;
223                 case HandleKind.GenericParameterConstraint: return HasCustomAttributeTag.GenericParamConstraint;
224                 case HandleKind.MethodSpecification: return HasCustomAttributeTag.MethodSpec;
225 
226                 default:
227                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
228                     return 0;
229             }
230         }
231 
232         private enum HasConstantTag
233         {
234             Field = 0,
235             Param = 1,
236             Property = 2,
237 
238             BitCount = 2
239         }
240 
ToHasConstantTag(HandleKind kind)241         private static HasConstantTag ToHasConstantTag(HandleKind kind)
242         {
243             switch (kind)
244             {
245                 case HandleKind.FieldDefinition: return HasConstantTag.Field;
246                 case HandleKind.Parameter: return HasConstantTag.Param;
247                 case HandleKind.PropertyDefinition: return HasConstantTag.Property;
248 
249                 default:
250                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
251                     return 0;
252             }
253         }
254 
255         private enum CustomAttributeTypeTag
256         {
257             MethodDef = 2,
258             MemberRef = 3,
259 
260             BitCount = 3
261         }
262 
ToCustomAttributeTypeTag(HandleKind kind)263         private static CustomAttributeTypeTag ToCustomAttributeTypeTag(HandleKind kind)
264         {
265             switch (kind)
266             {
267                 case HandleKind.MethodDefinition: return CustomAttributeTypeTag.MethodDef;
268                 case HandleKind.MemberReference: return CustomAttributeTypeTag.MemberRef;
269 
270                 default:
271                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
272                     return 0;
273             }
274         }
275 
276         private enum HasDeclSecurityTag
277         {
278             TypeDef = 0,
279             MethodDef = 1,
280             Assembly = 2,
281 
282             BitCount = 2
283         }
284 
ToHasDeclSecurityTag(HandleKind kind)285         private static HasDeclSecurityTag ToHasDeclSecurityTag(HandleKind kind)
286         {
287             switch (kind)
288             {
289                 case HandleKind.TypeDefinition: return HasDeclSecurityTag.TypeDef;
290                 case HandleKind.MethodDefinition: return HasDeclSecurityTag.MethodDef;
291                 case HandleKind.AssemblyDefinition: return HasDeclSecurityTag.Assembly;
292 
293                 default:
294                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
295                     return 0;
296             }
297         }
298 
299         private enum HasFieldMarshalTag
300         {
301             Field = 0,
302             Param = 1,
303 
304             BitCount = 1
305         }
306 
ToHasFieldMarshalTag(HandleKind kind)307         private static HasFieldMarshalTag ToHasFieldMarshalTag(HandleKind kind)
308         {
309             switch (kind)
310             {
311                 case HandleKind.FieldDefinition: return HasFieldMarshalTag.Field;
312                 case HandleKind.Parameter: return HasFieldMarshalTag.Param;
313 
314                 default:
315                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
316                     return 0;
317             }
318         }
319 
320         private enum HasSemanticsTag
321         {
322             Event = 0,
323             Property = 1,
324 
325             BitCount = 1
326         }
327 
ToHasSemanticsTag(HandleKind kind)328         private static HasSemanticsTag ToHasSemanticsTag(HandleKind kind)
329         {
330             switch (kind)
331             {
332                 case HandleKind.EventDefinition: return HasSemanticsTag.Event;
333                 case HandleKind.PropertyDefinition: return HasSemanticsTag.Property;
334 
335                 default:
336                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
337                     return 0;
338             }
339         }
340 
341         private enum ImplementationTag
342         {
343             File = 0,
344             AssemblyRef = 1,
345             ExportedType = 2,
346 
347             BitCount = 2
348         }
349 
ToImplementationTag(HandleKind kind)350         private static ImplementationTag ToImplementationTag(HandleKind kind)
351         {
352             switch (kind)
353             {
354                 case HandleKind.AssemblyFile: return ImplementationTag.File;
355                 case HandleKind.AssemblyReference: return ImplementationTag.AssemblyRef;
356                 case HandleKind.ExportedType: return ImplementationTag.ExportedType;
357 
358                 default:
359                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
360                     return 0;
361             }
362         }
363 
364         private enum MemberForwardedTag
365         {
366             Field = 0,
367             MethodDef = 1,
368 
369             BitCount = 1
370         }
371 
ToMemberForwardedTag(HandleKind kind)372         private static MemberForwardedTag ToMemberForwardedTag(HandleKind kind)
373         {
374             switch (kind)
375             {
376                 case HandleKind.FieldDefinition: return MemberForwardedTag.Field;
377                 case HandleKind.MethodDefinition: return MemberForwardedTag.MethodDef;
378 
379                 default:
380                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
381                     return 0;
382             }
383         }
384 
385         private enum MemberRefParentTag
386         {
387             TypeDef = 0,
388             TypeRef = 1,
389             ModuleRef = 2,
390             MethodDef = 3,
391             TypeSpec = 4,
392 
393             BitCount = 3
394         }
395 
ToMemberRefParentTag(HandleKind kind)396         private static MemberRefParentTag ToMemberRefParentTag(HandleKind kind)
397         {
398             switch (kind)
399             {
400                 case HandleKind.TypeDefinition: return MemberRefParentTag.TypeDef;
401                 case HandleKind.TypeReference: return MemberRefParentTag.TypeRef;
402                 case HandleKind.ModuleReference: return MemberRefParentTag.ModuleRef;
403                 case HandleKind.MethodDefinition: return MemberRefParentTag.MethodDef;
404                 case HandleKind.TypeSpecification: return MemberRefParentTag.TypeSpec;
405 
406                 default:
407                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
408                     return 0;
409             }
410         }
411 
412         private enum MethodDefOrRefTag
413         {
414             MethodDef = 0,
415             MemberRef = 1,
416 
417             BitCount = 1
418         }
419 
ToMethodDefOrRefTag(HandleKind kind)420         private static MethodDefOrRefTag ToMethodDefOrRefTag(HandleKind kind)
421         {
422             switch (kind)
423             {
424                 case HandleKind.MethodDefinition: return MethodDefOrRefTag.MethodDef;
425                 case HandleKind.MemberReference: return MethodDefOrRefTag.MemberRef;
426 
427                 default:
428                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
429                     return 0;
430             }
431         }
432 
433         private enum ResolutionScopeTag
434         {
435             Module = 0,
436             ModuleRef = 1,
437             AssemblyRef = 2,
438             TypeRef = 3,
439 
440             BitCount = 2
441         }
442 
ToResolutionScopeTag(HandleKind kind)443         private static ResolutionScopeTag ToResolutionScopeTag(HandleKind kind)
444         {
445             switch (kind)
446             {
447                 case HandleKind.ModuleDefinition: return ResolutionScopeTag.Module;
448                 case HandleKind.ModuleReference: return ResolutionScopeTag.ModuleRef;
449                 case HandleKind.AssemblyReference: return ResolutionScopeTag.AssemblyRef;
450                 case HandleKind.TypeReference: return ResolutionScopeTag.TypeRef;
451 
452                 default:
453                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
454                     return 0;
455             }
456         }
457 
458         private enum TypeDefOrRefOrSpecTag
459         {
460             TypeDef = 0,
461             TypeRef = 1,
462             TypeSpec = 2,
463 
464             BitCount = 2
465         }
466 
ToTypeDefOrRefOrSpecTag(HandleKind kind)467         private static TypeDefOrRefOrSpecTag ToTypeDefOrRefOrSpecTag(HandleKind kind)
468         {
469             switch (kind)
470             {
471                 case HandleKind.TypeDefinition: return TypeDefOrRefOrSpecTag.TypeDef;
472                 case HandleKind.TypeReference: return TypeDefOrRefOrSpecTag.TypeRef;
473                 case HandleKind.TypeSpecification: return TypeDefOrRefOrSpecTag.TypeSpec;
474 
475                 default:
476                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
477                     return 0;
478             }
479         }
480 
481         private enum TypeDefOrRefTag
482         {
483             TypeDef = 0,
484             TypeRef = 1,
485 
486             BitCount = 2
487         }
488 
ToTypeDefOrRefTag(HandleKind kind)489         private static TypeDefOrRefTag ToTypeDefOrRefTag(HandleKind kind)
490         {
491             switch (kind)
492             {
493                 case HandleKind.TypeDefinition: return TypeDefOrRefTag.TypeDef;
494                 case HandleKind.TypeReference: return TypeDefOrRefTag.TypeRef;
495 
496                 default:
497                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
498                     return 0;
499             }
500         }
501 
502         private enum TypeOrMethodDefTag
503         {
504             TypeDef = 0,
505             MethodDef = 1,
506 
507             BitCount = 1
508         }
509 
ToTypeOrMethodDefTag(HandleKind kind)510         private static TypeOrMethodDefTag ToTypeOrMethodDefTag(HandleKind kind)
511         {
512             switch (kind)
513             {
514                 case HandleKind.TypeDefinition: return TypeOrMethodDefTag.TypeDef;
515                 case HandleKind.MethodDefinition: return TypeOrMethodDefTag.MethodDef;
516 
517                 default:
518                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
519                     return 0;
520             }
521         }
522 
523         private enum HasCustomDebugInformationTag
524         {
525             MethodDef = 0,
526             Field = 1,
527             TypeRef = 2,
528             TypeDef = 3,
529             Param = 4,
530             InterfaceImpl = 5,
531             MemberRef = 6,
532             Module = 7,
533             DeclSecurity = 8,
534             Property = 9,
535             Event = 10,
536             StandAloneSig = 11,
537             ModuleRef = 12,
538             TypeSpec = 13,
539             Assembly = 14,
540             AssemblyRef = 15,
541             File = 16,
542             ExportedType = 17,
543             ManifestResource = 18,
544             GenericParam = 19,
545             GenericParamConstraint = 20,
546             MethodSpec = 21,
547             Document = 22,
548             LocalScope = 23,
549             LocalVariable = 24,
550             LocalConstant = 25,
551             ImportScope = 26,
552 
553             BitCount = 5
554         }
555 
ToHasCustomDebugInformationTag(HandleKind kind)556         private static HasCustomDebugInformationTag ToHasCustomDebugInformationTag(HandleKind kind)
557         {
558             switch (kind)
559             {
560                 case HandleKind.MethodDefinition: return HasCustomDebugInformationTag.MethodDef;
561                 case HandleKind.FieldDefinition: return HasCustomDebugInformationTag.Field;
562                 case HandleKind.TypeReference: return HasCustomDebugInformationTag.TypeRef;
563                 case HandleKind.TypeDefinition: return HasCustomDebugInformationTag.TypeDef;
564                 case HandleKind.Parameter: return HasCustomDebugInformationTag.Param;
565                 case HandleKind.InterfaceImplementation: return HasCustomDebugInformationTag.InterfaceImpl;
566                 case HandleKind.MemberReference: return HasCustomDebugInformationTag.MemberRef;
567                 case HandleKind.ModuleDefinition: return HasCustomDebugInformationTag.Module;
568                 case HandleKind.DeclarativeSecurityAttribute: return HasCustomDebugInformationTag.DeclSecurity;
569                 case HandleKind.PropertyDefinition: return HasCustomDebugInformationTag.Property;
570                 case HandleKind.EventDefinition: return HasCustomDebugInformationTag.Event;
571                 case HandleKind.StandaloneSignature: return HasCustomDebugInformationTag.StandAloneSig;
572                 case HandleKind.ModuleReference: return HasCustomDebugInformationTag.ModuleRef;
573                 case HandleKind.TypeSpecification: return HasCustomDebugInformationTag.TypeSpec;
574                 case HandleKind.AssemblyDefinition: return HasCustomDebugInformationTag.Assembly;
575                 case HandleKind.AssemblyReference: return HasCustomDebugInformationTag.AssemblyRef;
576                 case HandleKind.AssemblyFile: return HasCustomDebugInformationTag.File;
577                 case HandleKind.ExportedType: return HasCustomDebugInformationTag.ExportedType;
578                 case HandleKind.ManifestResource: return HasCustomDebugInformationTag.ManifestResource;
579                 case HandleKind.GenericParameter: return HasCustomDebugInformationTag.GenericParam;
580                 case HandleKind.GenericParameterConstraint: return HasCustomDebugInformationTag.GenericParamConstraint;
581                 case HandleKind.MethodSpecification: return HasCustomDebugInformationTag.MethodSpec;
582                 case HandleKind.Document: return HasCustomDebugInformationTag.Document;
583                 case HandleKind.LocalScope: return HasCustomDebugInformationTag.LocalScope;
584                 case HandleKind.LocalVariable: return HasCustomDebugInformationTag.LocalVariable;
585                 case HandleKind.LocalConstant: return HasCustomDebugInformationTag.LocalConstant;
586                 case HandleKind.ImportScope: return HasCustomDebugInformationTag.ImportScope;
587 
588                 default:
589                     Throw.InvalidArgument_UnexpectedHandleKind(kind);
590                     return 0;
591             }
592         }
593     }
594 }
595