| | | 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 | | |
| | | 4 | | using System.Buffers.Binary; |
| | | 5 | | using System.Diagnostics; |
| | | 6 | | using System.Diagnostics.CodeAnalysis; |
| | | 7 | | using System.Reflection.Metadata.Ecma335; |
| | | 8 | | |
| | | 9 | | namespace System.Reflection.Metadata |
| | | 10 | | { |
| | | 11 | | public readonly struct ModuleDefinitionHandle : IEquatable<ModuleDefinitionHandle> |
| | | 12 | | { |
| | | 13 | | private const uint tokenType = TokenTypeIds.Module; |
| | | 14 | | private const byte tokenTypeSmall = (byte)HandleType.Module; |
| | | 15 | | private readonly int _rowId; |
| | | 16 | | |
| | | 17 | | internal ModuleDefinitionHandle(int rowId) |
| | | 18 | | { |
| | | 19 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 20 | | _rowId = rowId; |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | internal static ModuleDefinitionHandle FromRowId(int rowId) |
| | | 24 | | { |
| | | 25 | | return new ModuleDefinitionHandle(rowId); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public static implicit operator Handle(ModuleDefinitionHandle handle) |
| | | 29 | | { |
| | | 30 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public static implicit operator EntityHandle(ModuleDefinitionHandle handle) |
| | | 34 | | { |
| | | 35 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public static explicit operator ModuleDefinitionHandle(Handle handle) |
| | | 39 | | { |
| | | 40 | | if (handle.VType != tokenTypeSmall) |
| | | 41 | | { |
| | | 42 | | Throw.InvalidCast(); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | return new ModuleDefinitionHandle(handle.RowId); |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | public static explicit operator ModuleDefinitionHandle(EntityHandle handle) |
| | | 49 | | { |
| | | 50 | | if (handle.VType != tokenType) |
| | | 51 | | { |
| | | 52 | | Throw.InvalidCast(); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | return new ModuleDefinitionHandle(handle.RowId); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | public bool IsNil |
| | | 59 | | { |
| | | 60 | | get |
| | | 61 | | { |
| | | 62 | | return RowId == 0; |
| | | 63 | | } |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | internal int RowId { get { return _rowId; } } |
| | | 67 | | |
| | | 68 | | public static bool operator ==(ModuleDefinitionHandle left, ModuleDefinitionHandle right) |
| | | 69 | | { |
| | | 70 | | return left._rowId == right._rowId; |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | public override bool Equals(object? obj) |
| | | 74 | | { |
| | | 75 | | return obj is ModuleDefinitionHandle moduleDefinition && moduleDefinition._rowId == _rowId; |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | public bool Equals(ModuleDefinitionHandle other) |
| | | 79 | | { |
| | | 80 | | return _rowId == other._rowId; |
| | | 81 | | } |
| | | 82 | | |
| | | 83 | | public override int GetHashCode() |
| | | 84 | | { |
| | | 85 | | return _rowId.GetHashCode(); |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | public static bool operator !=(ModuleDefinitionHandle left, ModuleDefinitionHandle right) |
| | | 89 | | { |
| | | 90 | | return left._rowId != right._rowId; |
| | | 91 | | } |
| | | 92 | | } |
| | | 93 | | |
| | | 94 | | public readonly struct AssemblyDefinitionHandle : IEquatable<AssemblyDefinitionHandle> |
| | | 95 | | { |
| | | 96 | | private const uint tokenType = TokenTypeIds.Assembly; |
| | | 97 | | private const byte tokenTypeSmall = (byte)HandleType.Assembly; |
| | | 98 | | private readonly int _rowId; |
| | | 99 | | |
| | | 100 | | internal AssemblyDefinitionHandle(int rowId) |
| | 0 | 101 | | { |
| | 0 | 102 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | 0 | 103 | | _rowId = rowId; |
| | 0 | 104 | | } |
| | | 105 | | |
| | | 106 | | internal static AssemblyDefinitionHandle FromRowId(int rowId) |
| | 0 | 107 | | { |
| | 0 | 108 | | return new AssemblyDefinitionHandle(rowId); |
| | 0 | 109 | | } |
| | | 110 | | |
| | | 111 | | public static implicit operator Handle(AssemblyDefinitionHandle handle) |
| | 0 | 112 | | { |
| | 0 | 113 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | 0 | 114 | | } |
| | | 115 | | |
| | | 116 | | public static implicit operator EntityHandle(AssemblyDefinitionHandle handle) |
| | 0 | 117 | | { |
| | 0 | 118 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | 0 | 119 | | } |
| | | 120 | | |
| | | 121 | | public static explicit operator AssemblyDefinitionHandle(Handle handle) |
| | 0 | 122 | | { |
| | 0 | 123 | | if (handle.VType != tokenTypeSmall) |
| | 0 | 124 | | { |
| | 0 | 125 | | Throw.InvalidCast(); |
| | | 126 | | } |
| | | 127 | | |
| | 0 | 128 | | return new AssemblyDefinitionHandle(handle.RowId); |
| | 0 | 129 | | } |
| | | 130 | | |
| | | 131 | | public static explicit operator AssemblyDefinitionHandle(EntityHandle handle) |
| | 0 | 132 | | { |
| | 0 | 133 | | if (handle.VType != tokenType) |
| | 0 | 134 | | { |
| | 0 | 135 | | Throw.InvalidCast(); |
| | | 136 | | } |
| | | 137 | | |
| | 0 | 138 | | return new AssemblyDefinitionHandle(handle.RowId); |
| | 0 | 139 | | } |
| | | 140 | | |
| | | 141 | | public bool IsNil |
| | | 142 | | { |
| | | 143 | | get |
| | 0 | 144 | | { |
| | 0 | 145 | | return RowId == 0; |
| | 0 | 146 | | } |
| | | 147 | | } |
| | | 148 | | |
| | 0 | 149 | | internal int RowId { get { return _rowId; } } |
| | | 150 | | |
| | | 151 | | public static bool operator ==(AssemblyDefinitionHandle left, AssemblyDefinitionHandle right) |
| | 0 | 152 | | { |
| | 0 | 153 | | return left._rowId == right._rowId; |
| | 0 | 154 | | } |
| | | 155 | | |
| | | 156 | | public override bool Equals(object? obj) |
| | 0 | 157 | | { |
| | 0 | 158 | | return obj is AssemblyDefinitionHandle && ((AssemblyDefinitionHandle)obj)._rowId == _rowId; |
| | 0 | 159 | | } |
| | | 160 | | |
| | | 161 | | public bool Equals(AssemblyDefinitionHandle other) |
| | 0 | 162 | | { |
| | 0 | 163 | | return _rowId == other._rowId; |
| | 0 | 164 | | } |
| | | 165 | | |
| | | 166 | | public override int GetHashCode() |
| | 0 | 167 | | { |
| | 0 | 168 | | return _rowId.GetHashCode(); |
| | 0 | 169 | | } |
| | | 170 | | |
| | | 171 | | public static bool operator !=(AssemblyDefinitionHandle left, AssemblyDefinitionHandle right) |
| | 0 | 172 | | { |
| | 0 | 173 | | return left._rowId != right._rowId; |
| | 0 | 174 | | } |
| | | 175 | | } |
| | | 176 | | |
| | | 177 | | public readonly struct InterfaceImplementationHandle : IEquatable<InterfaceImplementationHandle> |
| | | 178 | | { |
| | | 179 | | private const uint tokenType = TokenTypeIds.InterfaceImpl; |
| | | 180 | | private const byte tokenTypeSmall = (byte)HandleType.InterfaceImpl; |
| | | 181 | | private readonly int _rowId; |
| | | 182 | | |
| | | 183 | | internal InterfaceImplementationHandle(int rowId) |
| | | 184 | | { |
| | | 185 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 186 | | _rowId = rowId; |
| | | 187 | | } |
| | | 188 | | |
| | | 189 | | internal static InterfaceImplementationHandle FromRowId(int rowId) |
| | | 190 | | { |
| | | 191 | | return new InterfaceImplementationHandle(rowId); |
| | | 192 | | } |
| | | 193 | | |
| | | 194 | | public static implicit operator Handle(InterfaceImplementationHandle handle) |
| | | 195 | | { |
| | | 196 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 197 | | } |
| | | 198 | | |
| | | 199 | | public static implicit operator EntityHandle(InterfaceImplementationHandle handle) |
| | | 200 | | { |
| | | 201 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 202 | | } |
| | | 203 | | |
| | | 204 | | public static explicit operator InterfaceImplementationHandle(Handle handle) |
| | | 205 | | { |
| | | 206 | | if (handle.VType != tokenTypeSmall) |
| | | 207 | | { |
| | | 208 | | Throw.InvalidCast(); |
| | | 209 | | } |
| | | 210 | | |
| | | 211 | | return new InterfaceImplementationHandle(handle.RowId); |
| | | 212 | | } |
| | | 213 | | |
| | | 214 | | public static explicit operator InterfaceImplementationHandle(EntityHandle handle) |
| | | 215 | | { |
| | | 216 | | if (handle.VType != tokenType) |
| | | 217 | | { |
| | | 218 | | Throw.InvalidCast(); |
| | | 219 | | } |
| | | 220 | | |
| | | 221 | | return new InterfaceImplementationHandle(handle.RowId); |
| | | 222 | | } |
| | | 223 | | |
| | | 224 | | public bool IsNil |
| | | 225 | | { |
| | | 226 | | get |
| | | 227 | | { |
| | | 228 | | return RowId == 0; |
| | | 229 | | } |
| | | 230 | | } |
| | | 231 | | |
| | | 232 | | internal int RowId { get { return _rowId; } } |
| | | 233 | | |
| | | 234 | | public static bool operator ==(InterfaceImplementationHandle left, InterfaceImplementationHandle right) |
| | | 235 | | { |
| | | 236 | | return left._rowId == right._rowId; |
| | | 237 | | } |
| | | 238 | | |
| | | 239 | | public override bool Equals(object? obj) |
| | | 240 | | { |
| | | 241 | | return obj is InterfaceImplementationHandle && ((InterfaceImplementationHandle)obj)._rowId == _rowId; |
| | | 242 | | } |
| | | 243 | | |
| | | 244 | | public bool Equals(InterfaceImplementationHandle other) |
| | | 245 | | { |
| | | 246 | | return _rowId == other._rowId; |
| | | 247 | | } |
| | | 248 | | |
| | | 249 | | public override int GetHashCode() |
| | | 250 | | { |
| | | 251 | | return _rowId.GetHashCode(); |
| | | 252 | | } |
| | | 253 | | |
| | | 254 | | public static bool operator !=(InterfaceImplementationHandle left, InterfaceImplementationHandle right) |
| | | 255 | | { |
| | | 256 | | return left._rowId != right._rowId; |
| | | 257 | | } |
| | | 258 | | } |
| | | 259 | | |
| | | 260 | | public readonly struct MethodDefinitionHandle : IEquatable<MethodDefinitionHandle> |
| | | 261 | | { |
| | | 262 | | private const uint tokenType = TokenTypeIds.MethodDef; |
| | | 263 | | private const byte tokenTypeSmall = (byte)HandleType.MethodDef; |
| | | 264 | | private readonly int _rowId; |
| | | 265 | | |
| | | 266 | | private MethodDefinitionHandle(int rowId) |
| | | 267 | | { |
| | | 268 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 269 | | _rowId = rowId; |
| | | 270 | | } |
| | | 271 | | |
| | | 272 | | internal static MethodDefinitionHandle FromRowId(int rowId) |
| | | 273 | | { |
| | | 274 | | return new MethodDefinitionHandle(rowId); |
| | | 275 | | } |
| | | 276 | | |
| | | 277 | | public static implicit operator Handle(MethodDefinitionHandle handle) |
| | | 278 | | { |
| | | 279 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 280 | | } |
| | | 281 | | |
| | | 282 | | public static implicit operator EntityHandle(MethodDefinitionHandle handle) |
| | | 283 | | { |
| | | 284 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 285 | | } |
| | | 286 | | |
| | | 287 | | public static explicit operator MethodDefinitionHandle(Handle handle) |
| | | 288 | | { |
| | | 289 | | if (handle.VType != tokenTypeSmall) |
| | | 290 | | { |
| | | 291 | | Throw.InvalidCast(); |
| | | 292 | | } |
| | | 293 | | |
| | | 294 | | return new MethodDefinitionHandle(handle.RowId); |
| | | 295 | | } |
| | | 296 | | |
| | | 297 | | public static explicit operator MethodDefinitionHandle(EntityHandle handle) |
| | | 298 | | { |
| | | 299 | | if (handle.VType != tokenType) |
| | | 300 | | { |
| | | 301 | | Throw.InvalidCast(); |
| | | 302 | | } |
| | | 303 | | |
| | | 304 | | return new MethodDefinitionHandle(handle.RowId); |
| | | 305 | | } |
| | | 306 | | |
| | | 307 | | public bool IsNil |
| | | 308 | | { |
| | | 309 | | get |
| | | 310 | | { |
| | | 311 | | return RowId == 0; |
| | | 312 | | } |
| | | 313 | | } |
| | | 314 | | |
| | | 315 | | internal int RowId { get { return _rowId; } } |
| | | 316 | | |
| | | 317 | | public static bool operator ==(MethodDefinitionHandle left, MethodDefinitionHandle right) |
| | | 318 | | { |
| | | 319 | | return left._rowId == right._rowId; |
| | | 320 | | } |
| | | 321 | | |
| | | 322 | | public override bool Equals(object? obj) |
| | | 323 | | { |
| | | 324 | | return obj is MethodDefinitionHandle && ((MethodDefinitionHandle)obj)._rowId == _rowId; |
| | | 325 | | } |
| | | 326 | | |
| | | 327 | | public bool Equals(MethodDefinitionHandle other) |
| | | 328 | | { |
| | | 329 | | return _rowId == other._rowId; |
| | | 330 | | } |
| | | 331 | | |
| | | 332 | | public override int GetHashCode() |
| | | 333 | | { |
| | | 334 | | return _rowId.GetHashCode(); |
| | | 335 | | } |
| | | 336 | | |
| | | 337 | | public static bool operator !=(MethodDefinitionHandle left, MethodDefinitionHandle right) |
| | | 338 | | { |
| | | 339 | | return left._rowId != right._rowId; |
| | | 340 | | } |
| | | 341 | | |
| | | 342 | | /// <summary> |
| | | 343 | | /// Returns a handle to <see cref="MethodDebugInformation"/> corresponding to this handle. |
| | | 344 | | /// </summary> |
| | | 345 | | /// <remarks> |
| | | 346 | | /// The resulting handle is only valid within the context of a <see cref="MetadataReader"/> open on the Portable |
| | | 347 | | /// which in case of standalone PDB file is a different reader than the one containing this method definition. |
| | | 348 | | /// </remarks> |
| | | 349 | | public MethodDebugInformationHandle ToDebugInformationHandle() |
| | | 350 | | { |
| | | 351 | | return MethodDebugInformationHandle.FromRowId(_rowId); |
| | | 352 | | } |
| | | 353 | | } |
| | | 354 | | |
| | | 355 | | public readonly struct MethodImplementationHandle : IEquatable<MethodImplementationHandle> |
| | | 356 | | { |
| | | 357 | | private const uint tokenType = TokenTypeIds.MethodImpl; |
| | | 358 | | private const byte tokenTypeSmall = (byte)HandleType.MethodImpl; |
| | | 359 | | private readonly int _rowId; |
| | | 360 | | |
| | | 361 | | private MethodImplementationHandle(int rowId) |
| | | 362 | | { |
| | | 363 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 364 | | _rowId = rowId; |
| | | 365 | | } |
| | | 366 | | |
| | | 367 | | internal static MethodImplementationHandle FromRowId(int rowId) |
| | | 368 | | { |
| | | 369 | | return new MethodImplementationHandle(rowId); |
| | | 370 | | } |
| | | 371 | | |
| | | 372 | | public static implicit operator Handle(MethodImplementationHandle handle) |
| | | 373 | | { |
| | | 374 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 375 | | } |
| | | 376 | | |
| | | 377 | | public static implicit operator EntityHandle(MethodImplementationHandle handle) |
| | | 378 | | { |
| | | 379 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 380 | | } |
| | | 381 | | |
| | | 382 | | public static explicit operator MethodImplementationHandle(Handle handle) |
| | | 383 | | { |
| | | 384 | | if (handle.VType != tokenTypeSmall) |
| | | 385 | | { |
| | | 386 | | Throw.InvalidCast(); |
| | | 387 | | } |
| | | 388 | | |
| | | 389 | | return new MethodImplementationHandle(handle.RowId); |
| | | 390 | | } |
| | | 391 | | |
| | | 392 | | public static explicit operator MethodImplementationHandle(EntityHandle handle) |
| | | 393 | | { |
| | | 394 | | if (handle.VType != tokenType) |
| | | 395 | | { |
| | | 396 | | Throw.InvalidCast(); |
| | | 397 | | } |
| | | 398 | | |
| | | 399 | | return new MethodImplementationHandle(handle.RowId); |
| | | 400 | | } |
| | | 401 | | |
| | | 402 | | public bool IsNil |
| | | 403 | | { |
| | | 404 | | get |
| | | 405 | | { |
| | | 406 | | return RowId == 0; |
| | | 407 | | } |
| | | 408 | | } |
| | | 409 | | |
| | | 410 | | internal int RowId { get { return _rowId; } } |
| | | 411 | | |
| | | 412 | | public static bool operator ==(MethodImplementationHandle left, MethodImplementationHandle right) |
| | | 413 | | { |
| | | 414 | | return left._rowId == right._rowId; |
| | | 415 | | } |
| | | 416 | | |
| | | 417 | | public override bool Equals(object? obj) |
| | | 418 | | { |
| | | 419 | | return obj is MethodImplementationHandle && ((MethodImplementationHandle)obj)._rowId == _rowId; |
| | | 420 | | } |
| | | 421 | | |
| | | 422 | | public bool Equals(MethodImplementationHandle other) |
| | | 423 | | { |
| | | 424 | | return _rowId == other._rowId; |
| | | 425 | | } |
| | | 426 | | |
| | | 427 | | public override int GetHashCode() |
| | | 428 | | { |
| | | 429 | | return _rowId.GetHashCode(); |
| | | 430 | | } |
| | | 431 | | |
| | | 432 | | public static bool operator !=(MethodImplementationHandle left, MethodImplementationHandle right) |
| | | 433 | | { |
| | | 434 | | return left._rowId != right._rowId; |
| | | 435 | | } |
| | | 436 | | } |
| | | 437 | | |
| | | 438 | | public readonly struct MethodSpecificationHandle : IEquatable<MethodSpecificationHandle> |
| | | 439 | | { |
| | | 440 | | private const uint tokenType = TokenTypeIds.MethodSpec; |
| | | 441 | | private const byte tokenTypeSmall = (byte)HandleType.MethodSpec; |
| | | 442 | | private readonly int _rowId; |
| | | 443 | | |
| | | 444 | | private MethodSpecificationHandle(int rowId) |
| | | 445 | | { |
| | | 446 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 447 | | _rowId = rowId; |
| | | 448 | | } |
| | | 449 | | |
| | | 450 | | internal static MethodSpecificationHandle FromRowId(int rowId) |
| | | 451 | | { |
| | | 452 | | return new MethodSpecificationHandle(rowId); |
| | | 453 | | } |
| | | 454 | | |
| | | 455 | | public static implicit operator Handle(MethodSpecificationHandle handle) |
| | | 456 | | { |
| | | 457 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 458 | | } |
| | | 459 | | |
| | | 460 | | public static implicit operator EntityHandle(MethodSpecificationHandle handle) |
| | | 461 | | { |
| | | 462 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 463 | | } |
| | | 464 | | |
| | | 465 | | public static explicit operator MethodSpecificationHandle(Handle handle) |
| | | 466 | | { |
| | | 467 | | if (handle.VType != tokenTypeSmall) |
| | | 468 | | { |
| | | 469 | | Throw.InvalidCast(); |
| | | 470 | | } |
| | | 471 | | |
| | | 472 | | return new MethodSpecificationHandle(handle.RowId); |
| | | 473 | | } |
| | | 474 | | |
| | | 475 | | public static explicit operator MethodSpecificationHandle(EntityHandle handle) |
| | | 476 | | { |
| | | 477 | | if (handle.VType != tokenType) |
| | | 478 | | { |
| | | 479 | | Throw.InvalidCast(); |
| | | 480 | | } |
| | | 481 | | |
| | | 482 | | return new MethodSpecificationHandle(handle.RowId); |
| | | 483 | | } |
| | | 484 | | |
| | | 485 | | public bool IsNil |
| | | 486 | | { |
| | | 487 | | get |
| | | 488 | | { |
| | | 489 | | return RowId == 0; |
| | | 490 | | } |
| | | 491 | | } |
| | | 492 | | |
| | | 493 | | internal int RowId { get { return _rowId; } } |
| | | 494 | | |
| | | 495 | | public static bool operator ==(MethodSpecificationHandle left, MethodSpecificationHandle right) |
| | | 496 | | { |
| | | 497 | | return left._rowId == right._rowId; |
| | | 498 | | } |
| | | 499 | | |
| | | 500 | | public override bool Equals(object? obj) |
| | | 501 | | { |
| | | 502 | | return obj is MethodSpecificationHandle && ((MethodSpecificationHandle)obj)._rowId == _rowId; |
| | | 503 | | } |
| | | 504 | | |
| | | 505 | | public bool Equals(MethodSpecificationHandle other) |
| | | 506 | | { |
| | | 507 | | return _rowId == other._rowId; |
| | | 508 | | } |
| | | 509 | | |
| | | 510 | | public override int GetHashCode() |
| | | 511 | | { |
| | | 512 | | return _rowId.GetHashCode(); |
| | | 513 | | } |
| | | 514 | | |
| | | 515 | | public static bool operator !=(MethodSpecificationHandle left, MethodSpecificationHandle right) |
| | | 516 | | { |
| | | 517 | | return left._rowId != right._rowId; |
| | | 518 | | } |
| | | 519 | | } |
| | | 520 | | |
| | | 521 | | public readonly struct TypeDefinitionHandle : IEquatable<TypeDefinitionHandle> |
| | | 522 | | { |
| | | 523 | | private const uint tokenType = TokenTypeIds.TypeDef; |
| | | 524 | | private const byte tokenTypeSmall = (byte)HandleType.TypeDef; |
| | | 525 | | private readonly int _rowId; |
| | | 526 | | |
| | | 527 | | private TypeDefinitionHandle(int rowId) |
| | | 528 | | { |
| | | 529 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 530 | | _rowId = rowId; |
| | | 531 | | } |
| | | 532 | | |
| | | 533 | | internal static TypeDefinitionHandle FromRowId(int rowId) |
| | | 534 | | { |
| | | 535 | | return new TypeDefinitionHandle(rowId); |
| | | 536 | | } |
| | | 537 | | |
| | | 538 | | public static implicit operator Handle(TypeDefinitionHandle handle) |
| | | 539 | | { |
| | | 540 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 541 | | } |
| | | 542 | | |
| | | 543 | | public static implicit operator EntityHandle(TypeDefinitionHandle handle) |
| | | 544 | | { |
| | | 545 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 546 | | } |
| | | 547 | | |
| | | 548 | | public static explicit operator TypeDefinitionHandle(Handle handle) |
| | | 549 | | { |
| | | 550 | | if (handle.VType != tokenTypeSmall) |
| | | 551 | | { |
| | | 552 | | Throw.InvalidCast(); |
| | | 553 | | } |
| | | 554 | | |
| | | 555 | | return new TypeDefinitionHandle(handle.RowId); |
| | | 556 | | } |
| | | 557 | | |
| | | 558 | | public static explicit operator TypeDefinitionHandle(EntityHandle handle) |
| | | 559 | | { |
| | | 560 | | if (handle.VType != tokenType) |
| | | 561 | | { |
| | | 562 | | Throw.InvalidCast(); |
| | | 563 | | } |
| | | 564 | | |
| | | 565 | | return new TypeDefinitionHandle(handle.RowId); |
| | | 566 | | } |
| | | 567 | | |
| | | 568 | | public bool IsNil |
| | | 569 | | { |
| | | 570 | | get |
| | | 571 | | { |
| | | 572 | | return RowId == 0; |
| | | 573 | | } |
| | | 574 | | } |
| | | 575 | | |
| | | 576 | | internal int RowId { get { return _rowId; } } |
| | | 577 | | |
| | | 578 | | public static bool operator ==(TypeDefinitionHandle left, TypeDefinitionHandle right) |
| | | 579 | | { |
| | | 580 | | return left._rowId == right._rowId; |
| | | 581 | | } |
| | | 582 | | |
| | | 583 | | public override bool Equals(object? obj) |
| | | 584 | | { |
| | | 585 | | return obj is TypeDefinitionHandle && ((TypeDefinitionHandle)obj)._rowId == _rowId; |
| | | 586 | | } |
| | | 587 | | |
| | | 588 | | public bool Equals(TypeDefinitionHandle other) |
| | | 589 | | { |
| | | 590 | | return _rowId == other._rowId; |
| | | 591 | | } |
| | | 592 | | |
| | | 593 | | public override int GetHashCode() |
| | | 594 | | { |
| | | 595 | | return _rowId.GetHashCode(); |
| | | 596 | | } |
| | | 597 | | |
| | | 598 | | public static bool operator !=(TypeDefinitionHandle left, TypeDefinitionHandle right) |
| | | 599 | | { |
| | | 600 | | return left._rowId != right._rowId; |
| | | 601 | | } |
| | | 602 | | } |
| | | 603 | | |
| | | 604 | | public readonly struct ExportedTypeHandle : IEquatable<ExportedTypeHandle> |
| | | 605 | | { |
| | | 606 | | private const uint tokenType = TokenTypeIds.ExportedType; |
| | | 607 | | private const byte tokenTypeSmall = (byte)HandleType.ExportedType; |
| | | 608 | | private readonly int _rowId; |
| | | 609 | | |
| | | 610 | | private ExportedTypeHandle(int rowId) |
| | | 611 | | { |
| | | 612 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 613 | | _rowId = rowId; |
| | | 614 | | } |
| | | 615 | | |
| | | 616 | | internal static ExportedTypeHandle FromRowId(int rowId) |
| | | 617 | | { |
| | | 618 | | return new ExportedTypeHandle(rowId); |
| | | 619 | | } |
| | | 620 | | |
| | | 621 | | public static implicit operator Handle(ExportedTypeHandle handle) |
| | | 622 | | { |
| | | 623 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 624 | | } |
| | | 625 | | |
| | | 626 | | public static implicit operator EntityHandle(ExportedTypeHandle handle) |
| | | 627 | | { |
| | | 628 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 629 | | } |
| | | 630 | | |
| | | 631 | | public static explicit operator ExportedTypeHandle(Handle handle) |
| | | 632 | | { |
| | | 633 | | if (handle.VType != tokenTypeSmall) |
| | | 634 | | { |
| | | 635 | | Throw.InvalidCast(); |
| | | 636 | | } |
| | | 637 | | |
| | | 638 | | return new ExportedTypeHandle(handle.RowId); |
| | | 639 | | } |
| | | 640 | | |
| | | 641 | | public static explicit operator ExportedTypeHandle(EntityHandle handle) |
| | | 642 | | { |
| | | 643 | | if (handle.VType != tokenType) |
| | | 644 | | { |
| | | 645 | | Throw.InvalidCast(); |
| | | 646 | | } |
| | | 647 | | |
| | | 648 | | return new ExportedTypeHandle(handle.RowId); |
| | | 649 | | } |
| | | 650 | | |
| | | 651 | | public bool IsNil |
| | | 652 | | { |
| | | 653 | | get |
| | | 654 | | { |
| | | 655 | | return RowId == 0; |
| | | 656 | | } |
| | | 657 | | } |
| | | 658 | | |
| | | 659 | | internal int RowId { get { return _rowId; } } |
| | | 660 | | |
| | | 661 | | public static bool operator ==(ExportedTypeHandle left, ExportedTypeHandle right) |
| | | 662 | | { |
| | | 663 | | return left._rowId == right._rowId; |
| | | 664 | | } |
| | | 665 | | |
| | | 666 | | public override bool Equals(object? obj) |
| | | 667 | | { |
| | | 668 | | return obj is ExportedTypeHandle && ((ExportedTypeHandle)obj)._rowId == _rowId; |
| | | 669 | | } |
| | | 670 | | |
| | | 671 | | public bool Equals(ExportedTypeHandle other) |
| | | 672 | | { |
| | | 673 | | return _rowId == other._rowId; |
| | | 674 | | } |
| | | 675 | | |
| | | 676 | | public override int GetHashCode() |
| | | 677 | | { |
| | | 678 | | return _rowId.GetHashCode(); |
| | | 679 | | } |
| | | 680 | | |
| | | 681 | | public static bool operator !=(ExportedTypeHandle left, ExportedTypeHandle right) |
| | | 682 | | { |
| | | 683 | | return left._rowId != right._rowId; |
| | | 684 | | } |
| | | 685 | | } |
| | | 686 | | |
| | | 687 | | public readonly struct TypeReferenceHandle : IEquatable<TypeReferenceHandle> |
| | | 688 | | { |
| | | 689 | | private const uint tokenType = TokenTypeIds.TypeRef; |
| | | 690 | | private const byte tokenTypeSmall = (byte)HandleType.TypeRef; |
| | | 691 | | private readonly int _rowId; |
| | | 692 | | |
| | | 693 | | private TypeReferenceHandle(int rowId) |
| | | 694 | | { |
| | | 695 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 696 | | _rowId = rowId; |
| | | 697 | | } |
| | | 698 | | |
| | | 699 | | internal static TypeReferenceHandle FromRowId(int rowId) |
| | | 700 | | { |
| | | 701 | | return new TypeReferenceHandle(rowId); |
| | | 702 | | } |
| | | 703 | | |
| | | 704 | | public static implicit operator Handle(TypeReferenceHandle handle) |
| | | 705 | | { |
| | | 706 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 707 | | } |
| | | 708 | | |
| | | 709 | | public static implicit operator EntityHandle(TypeReferenceHandle handle) |
| | | 710 | | { |
| | | 711 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 712 | | } |
| | | 713 | | |
| | | 714 | | public static explicit operator TypeReferenceHandle(Handle handle) |
| | | 715 | | { |
| | | 716 | | if (handle.VType != tokenTypeSmall) |
| | | 717 | | { |
| | | 718 | | Throw.InvalidCast(); |
| | | 719 | | } |
| | | 720 | | |
| | | 721 | | return new TypeReferenceHandle(handle.RowId); |
| | | 722 | | } |
| | | 723 | | |
| | | 724 | | public static explicit operator TypeReferenceHandle(EntityHandle handle) |
| | | 725 | | { |
| | | 726 | | if (handle.VType != tokenType) |
| | | 727 | | { |
| | | 728 | | Throw.InvalidCast(); |
| | | 729 | | } |
| | | 730 | | |
| | | 731 | | return new TypeReferenceHandle(handle.RowId); |
| | | 732 | | } |
| | | 733 | | |
| | | 734 | | public bool IsNil |
| | | 735 | | { |
| | | 736 | | get |
| | | 737 | | { |
| | | 738 | | return RowId == 0; |
| | | 739 | | } |
| | | 740 | | } |
| | | 741 | | |
| | | 742 | | internal int RowId { get { return _rowId; } } |
| | | 743 | | |
| | | 744 | | public static bool operator ==(TypeReferenceHandle left, TypeReferenceHandle right) |
| | | 745 | | { |
| | | 746 | | return left._rowId == right._rowId; |
| | | 747 | | } |
| | | 748 | | |
| | | 749 | | public override bool Equals(object? obj) |
| | | 750 | | { |
| | | 751 | | return obj is TypeReferenceHandle && ((TypeReferenceHandle)obj)._rowId == _rowId; |
| | | 752 | | } |
| | | 753 | | |
| | | 754 | | public bool Equals(TypeReferenceHandle other) |
| | | 755 | | { |
| | | 756 | | return _rowId == other._rowId; |
| | | 757 | | } |
| | | 758 | | |
| | | 759 | | public override int GetHashCode() |
| | | 760 | | { |
| | | 761 | | return _rowId.GetHashCode(); |
| | | 762 | | } |
| | | 763 | | |
| | | 764 | | public static bool operator !=(TypeReferenceHandle left, TypeReferenceHandle right) |
| | | 765 | | { |
| | | 766 | | return left._rowId != right._rowId; |
| | | 767 | | } |
| | | 768 | | } |
| | | 769 | | |
| | | 770 | | public readonly struct TypeSpecificationHandle : IEquatable<TypeSpecificationHandle> |
| | | 771 | | { |
| | | 772 | | private const uint tokenType = TokenTypeIds.TypeSpec; |
| | | 773 | | private const byte tokenTypeSmall = (byte)HandleType.TypeSpec; |
| | | 774 | | private readonly int _rowId; |
| | | 775 | | |
| | | 776 | | private TypeSpecificationHandle(int rowId) |
| | | 777 | | { |
| | | 778 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 779 | | _rowId = rowId; |
| | | 780 | | } |
| | | 781 | | |
| | | 782 | | internal static TypeSpecificationHandle FromRowId(int rowId) |
| | | 783 | | { |
| | | 784 | | return new TypeSpecificationHandle(rowId); |
| | | 785 | | } |
| | | 786 | | |
| | | 787 | | public static implicit operator Handle(TypeSpecificationHandle handle) |
| | | 788 | | { |
| | | 789 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 790 | | } |
| | | 791 | | |
| | | 792 | | public static implicit operator EntityHandle(TypeSpecificationHandle handle) |
| | | 793 | | { |
| | | 794 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 795 | | } |
| | | 796 | | |
| | | 797 | | public static explicit operator TypeSpecificationHandle(Handle handle) |
| | | 798 | | { |
| | | 799 | | if (handle.VType != tokenTypeSmall) |
| | | 800 | | { |
| | | 801 | | Throw.InvalidCast(); |
| | | 802 | | } |
| | | 803 | | |
| | | 804 | | return new TypeSpecificationHandle(handle.RowId); |
| | | 805 | | } |
| | | 806 | | |
| | | 807 | | public static explicit operator TypeSpecificationHandle(EntityHandle handle) |
| | | 808 | | { |
| | | 809 | | if (handle.VType != tokenType) |
| | | 810 | | { |
| | | 811 | | Throw.InvalidCast(); |
| | | 812 | | } |
| | | 813 | | |
| | | 814 | | return new TypeSpecificationHandle(handle.RowId); |
| | | 815 | | } |
| | | 816 | | |
| | | 817 | | public bool IsNil |
| | | 818 | | { |
| | | 819 | | get |
| | | 820 | | { |
| | | 821 | | return RowId == 0; |
| | | 822 | | } |
| | | 823 | | } |
| | | 824 | | |
| | | 825 | | internal int RowId { get { return _rowId; } } |
| | | 826 | | |
| | | 827 | | public static bool operator ==(TypeSpecificationHandle left, TypeSpecificationHandle right) |
| | | 828 | | { |
| | | 829 | | return left._rowId == right._rowId; |
| | | 830 | | } |
| | | 831 | | |
| | | 832 | | public override bool Equals(object? obj) |
| | | 833 | | { |
| | | 834 | | return obj is TypeSpecificationHandle && ((TypeSpecificationHandle)obj)._rowId == _rowId; |
| | | 835 | | } |
| | | 836 | | |
| | | 837 | | public bool Equals(TypeSpecificationHandle other) |
| | | 838 | | { |
| | | 839 | | return _rowId == other._rowId; |
| | | 840 | | } |
| | | 841 | | |
| | | 842 | | public override int GetHashCode() |
| | | 843 | | { |
| | | 844 | | return _rowId.GetHashCode(); |
| | | 845 | | } |
| | | 846 | | |
| | | 847 | | public static bool operator !=(TypeSpecificationHandle left, TypeSpecificationHandle right) |
| | | 848 | | { |
| | | 849 | | return left._rowId != right._rowId; |
| | | 850 | | } |
| | | 851 | | } |
| | | 852 | | |
| | | 853 | | public readonly struct MemberReferenceHandle : IEquatable<MemberReferenceHandle> |
| | | 854 | | { |
| | | 855 | | private const uint tokenType = TokenTypeIds.MemberRef; |
| | | 856 | | private const byte tokenTypeSmall = (byte)HandleType.MemberRef; |
| | | 857 | | private readonly int _rowId; |
| | | 858 | | |
| | | 859 | | private MemberReferenceHandle(int rowId) |
| | | 860 | | { |
| | | 861 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 862 | | _rowId = rowId; |
| | | 863 | | } |
| | | 864 | | |
| | | 865 | | internal static MemberReferenceHandle FromRowId(int rowId) |
| | | 866 | | { |
| | | 867 | | return new MemberReferenceHandle(rowId); |
| | | 868 | | } |
| | | 869 | | |
| | | 870 | | public static implicit operator Handle(MemberReferenceHandle handle) |
| | | 871 | | { |
| | | 872 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 873 | | } |
| | | 874 | | |
| | | 875 | | public static implicit operator EntityHandle(MemberReferenceHandle handle) |
| | | 876 | | { |
| | | 877 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 878 | | } |
| | | 879 | | |
| | | 880 | | public static explicit operator MemberReferenceHandle(Handle handle) |
| | | 881 | | { |
| | | 882 | | if (handle.VType != tokenTypeSmall) |
| | | 883 | | { |
| | | 884 | | Throw.InvalidCast(); |
| | | 885 | | } |
| | | 886 | | |
| | | 887 | | return new MemberReferenceHandle(handle.RowId); |
| | | 888 | | } |
| | | 889 | | |
| | | 890 | | public static explicit operator MemberReferenceHandle(EntityHandle handle) |
| | | 891 | | { |
| | | 892 | | if (handle.VType != tokenType) |
| | | 893 | | { |
| | | 894 | | Throw.InvalidCast(); |
| | | 895 | | } |
| | | 896 | | |
| | | 897 | | return new MemberReferenceHandle(handle.RowId); |
| | | 898 | | } |
| | | 899 | | |
| | | 900 | | public bool IsNil |
| | | 901 | | { |
| | | 902 | | get |
| | | 903 | | { |
| | | 904 | | return RowId == 0; |
| | | 905 | | } |
| | | 906 | | } |
| | | 907 | | |
| | | 908 | | internal int RowId { get { return _rowId; } } |
| | | 909 | | |
| | | 910 | | public static bool operator ==(MemberReferenceHandle left, MemberReferenceHandle right) |
| | | 911 | | { |
| | | 912 | | return left._rowId == right._rowId; |
| | | 913 | | } |
| | | 914 | | |
| | | 915 | | public override bool Equals(object? obj) |
| | | 916 | | { |
| | | 917 | | return obj is MemberReferenceHandle && ((MemberReferenceHandle)obj)._rowId == _rowId; |
| | | 918 | | } |
| | | 919 | | |
| | | 920 | | public bool Equals(MemberReferenceHandle other) |
| | | 921 | | { |
| | | 922 | | return _rowId == other._rowId; |
| | | 923 | | } |
| | | 924 | | |
| | | 925 | | public override int GetHashCode() |
| | | 926 | | { |
| | | 927 | | return _rowId.GetHashCode(); |
| | | 928 | | } |
| | | 929 | | |
| | | 930 | | public static bool operator !=(MemberReferenceHandle left, MemberReferenceHandle right) |
| | | 931 | | { |
| | | 932 | | return left._rowId != right._rowId; |
| | | 933 | | } |
| | | 934 | | } |
| | | 935 | | |
| | | 936 | | public readonly struct FieldDefinitionHandle : IEquatable<FieldDefinitionHandle> |
| | | 937 | | { |
| | | 938 | | private const uint tokenType = TokenTypeIds.FieldDef; |
| | | 939 | | private const byte tokenTypeSmall = (byte)HandleType.FieldDef; |
| | | 940 | | private readonly int _rowId; |
| | | 941 | | |
| | | 942 | | private FieldDefinitionHandle(int rowId) |
| | | 943 | | { |
| | | 944 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 945 | | _rowId = rowId; |
| | | 946 | | } |
| | | 947 | | |
| | | 948 | | internal static FieldDefinitionHandle FromRowId(int rowId) |
| | | 949 | | { |
| | | 950 | | return new FieldDefinitionHandle(rowId); |
| | | 951 | | } |
| | | 952 | | |
| | | 953 | | public static implicit operator Handle(FieldDefinitionHandle handle) |
| | | 954 | | { |
| | | 955 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 956 | | } |
| | | 957 | | |
| | | 958 | | public static implicit operator EntityHandle(FieldDefinitionHandle handle) |
| | | 959 | | { |
| | | 960 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 961 | | } |
| | | 962 | | |
| | | 963 | | public static explicit operator FieldDefinitionHandle(Handle handle) |
| | | 964 | | { |
| | | 965 | | if (handle.VType != tokenTypeSmall) |
| | | 966 | | { |
| | | 967 | | Throw.InvalidCast(); |
| | | 968 | | } |
| | | 969 | | |
| | | 970 | | return new FieldDefinitionHandle(handle.RowId); |
| | | 971 | | } |
| | | 972 | | |
| | | 973 | | public static explicit operator FieldDefinitionHandle(EntityHandle handle) |
| | | 974 | | { |
| | | 975 | | if (handle.VType != tokenType) |
| | | 976 | | { |
| | | 977 | | Throw.InvalidCast(); |
| | | 978 | | } |
| | | 979 | | |
| | | 980 | | return new FieldDefinitionHandle(handle.RowId); |
| | | 981 | | } |
| | | 982 | | |
| | | 983 | | public bool IsNil |
| | | 984 | | { |
| | | 985 | | get |
| | | 986 | | { |
| | | 987 | | return RowId == 0; |
| | | 988 | | } |
| | | 989 | | } |
| | | 990 | | |
| | | 991 | | internal int RowId { get { return _rowId; } } |
| | | 992 | | |
| | | 993 | | public static bool operator ==(FieldDefinitionHandle left, FieldDefinitionHandle right) |
| | | 994 | | { |
| | | 995 | | return left._rowId == right._rowId; |
| | | 996 | | } |
| | | 997 | | |
| | | 998 | | public override bool Equals(object? obj) |
| | | 999 | | { |
| | | 1000 | | return obj is FieldDefinitionHandle && ((FieldDefinitionHandle)obj)._rowId == _rowId; |
| | | 1001 | | } |
| | | 1002 | | |
| | | 1003 | | public bool Equals(FieldDefinitionHandle other) |
| | | 1004 | | { |
| | | 1005 | | return _rowId == other._rowId; |
| | | 1006 | | } |
| | | 1007 | | |
| | | 1008 | | public override int GetHashCode() |
| | | 1009 | | { |
| | | 1010 | | return _rowId.GetHashCode(); |
| | | 1011 | | } |
| | | 1012 | | |
| | | 1013 | | public static bool operator !=(FieldDefinitionHandle left, FieldDefinitionHandle right) |
| | | 1014 | | { |
| | | 1015 | | return left._rowId != right._rowId; |
| | | 1016 | | } |
| | | 1017 | | } |
| | | 1018 | | |
| | | 1019 | | public readonly struct EventDefinitionHandle : IEquatable<EventDefinitionHandle> |
| | | 1020 | | { |
| | | 1021 | | private const uint tokenType = TokenTypeIds.Event; |
| | | 1022 | | private const byte tokenTypeSmall = (byte)HandleType.Event; |
| | | 1023 | | private readonly int _rowId; |
| | | 1024 | | |
| | | 1025 | | private EventDefinitionHandle(int rowId) |
| | | 1026 | | { |
| | | 1027 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1028 | | _rowId = rowId; |
| | | 1029 | | } |
| | | 1030 | | |
| | | 1031 | | internal static EventDefinitionHandle FromRowId(int rowId) |
| | | 1032 | | { |
| | | 1033 | | return new EventDefinitionHandle(rowId); |
| | | 1034 | | } |
| | | 1035 | | |
| | | 1036 | | public static implicit operator Handle(EventDefinitionHandle handle) |
| | | 1037 | | { |
| | | 1038 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1039 | | } |
| | | 1040 | | |
| | | 1041 | | public static implicit operator EntityHandle(EventDefinitionHandle handle) |
| | | 1042 | | { |
| | | 1043 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1044 | | } |
| | | 1045 | | |
| | | 1046 | | public static explicit operator EventDefinitionHandle(Handle handle) |
| | | 1047 | | { |
| | | 1048 | | if (handle.VType != tokenTypeSmall) |
| | | 1049 | | { |
| | | 1050 | | Throw.InvalidCast(); |
| | | 1051 | | } |
| | | 1052 | | |
| | | 1053 | | return new EventDefinitionHandle(handle.RowId); |
| | | 1054 | | } |
| | | 1055 | | |
| | | 1056 | | public static explicit operator EventDefinitionHandle(EntityHandle handle) |
| | | 1057 | | { |
| | | 1058 | | if (handle.VType != tokenType) |
| | | 1059 | | { |
| | | 1060 | | Throw.InvalidCast(); |
| | | 1061 | | } |
| | | 1062 | | |
| | | 1063 | | return new EventDefinitionHandle(handle.RowId); |
| | | 1064 | | } |
| | | 1065 | | |
| | | 1066 | | public bool IsNil |
| | | 1067 | | { |
| | | 1068 | | get |
| | | 1069 | | { |
| | | 1070 | | return RowId == 0; |
| | | 1071 | | } |
| | | 1072 | | } |
| | | 1073 | | |
| | | 1074 | | internal int RowId { get { return _rowId; } } |
| | | 1075 | | |
| | | 1076 | | public static bool operator ==(EventDefinitionHandle left, EventDefinitionHandle right) |
| | | 1077 | | { |
| | | 1078 | | return left._rowId == right._rowId; |
| | | 1079 | | } |
| | | 1080 | | |
| | | 1081 | | public override bool Equals(object? obj) |
| | | 1082 | | { |
| | | 1083 | | return obj is EventDefinitionHandle && ((EventDefinitionHandle)obj)._rowId == _rowId; |
| | | 1084 | | } |
| | | 1085 | | |
| | | 1086 | | public bool Equals(EventDefinitionHandle other) |
| | | 1087 | | { |
| | | 1088 | | return _rowId == other._rowId; |
| | | 1089 | | } |
| | | 1090 | | |
| | | 1091 | | public override int GetHashCode() |
| | | 1092 | | { |
| | | 1093 | | return _rowId.GetHashCode(); |
| | | 1094 | | } |
| | | 1095 | | |
| | | 1096 | | public static bool operator !=(EventDefinitionHandle left, EventDefinitionHandle right) |
| | | 1097 | | { |
| | | 1098 | | return left._rowId != right._rowId; |
| | | 1099 | | } |
| | | 1100 | | } |
| | | 1101 | | |
| | | 1102 | | public readonly struct PropertyDefinitionHandle : IEquatable<PropertyDefinitionHandle> |
| | | 1103 | | { |
| | | 1104 | | private const uint tokenType = TokenTypeIds.Property; |
| | | 1105 | | private const byte tokenTypeSmall = (byte)HandleType.Property; |
| | | 1106 | | private readonly int _rowId; |
| | | 1107 | | |
| | | 1108 | | private PropertyDefinitionHandle(int rowId) |
| | | 1109 | | { |
| | | 1110 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1111 | | _rowId = rowId; |
| | | 1112 | | } |
| | | 1113 | | |
| | | 1114 | | internal static PropertyDefinitionHandle FromRowId(int rowId) |
| | | 1115 | | { |
| | | 1116 | | return new PropertyDefinitionHandle(rowId); |
| | | 1117 | | } |
| | | 1118 | | |
| | | 1119 | | public static implicit operator Handle(PropertyDefinitionHandle handle) |
| | | 1120 | | { |
| | | 1121 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1122 | | } |
| | | 1123 | | |
| | | 1124 | | public static implicit operator EntityHandle(PropertyDefinitionHandle handle) |
| | | 1125 | | { |
| | | 1126 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1127 | | } |
| | | 1128 | | |
| | | 1129 | | public static explicit operator PropertyDefinitionHandle(Handle handle) |
| | | 1130 | | { |
| | | 1131 | | if (handle.VType != tokenTypeSmall) |
| | | 1132 | | { |
| | | 1133 | | Throw.InvalidCast(); |
| | | 1134 | | } |
| | | 1135 | | |
| | | 1136 | | return new PropertyDefinitionHandle(handle.RowId); |
| | | 1137 | | } |
| | | 1138 | | |
| | | 1139 | | public static explicit operator PropertyDefinitionHandle(EntityHandle handle) |
| | | 1140 | | { |
| | | 1141 | | if (handle.VType != tokenType) |
| | | 1142 | | { |
| | | 1143 | | Throw.InvalidCast(); |
| | | 1144 | | } |
| | | 1145 | | |
| | | 1146 | | return new PropertyDefinitionHandle(handle.RowId); |
| | | 1147 | | } |
| | | 1148 | | |
| | | 1149 | | public bool IsNil |
| | | 1150 | | { |
| | | 1151 | | get |
| | | 1152 | | { |
| | | 1153 | | return RowId == 0; |
| | | 1154 | | } |
| | | 1155 | | } |
| | | 1156 | | |
| | | 1157 | | internal int RowId { get { return _rowId; } } |
| | | 1158 | | |
| | | 1159 | | public static bool operator ==(PropertyDefinitionHandle left, PropertyDefinitionHandle right) |
| | | 1160 | | { |
| | | 1161 | | return left._rowId == right._rowId; |
| | | 1162 | | } |
| | | 1163 | | |
| | | 1164 | | public override bool Equals(object? obj) |
| | | 1165 | | { |
| | | 1166 | | return obj is PropertyDefinitionHandle && ((PropertyDefinitionHandle)obj)._rowId == _rowId; |
| | | 1167 | | } |
| | | 1168 | | |
| | | 1169 | | public bool Equals(PropertyDefinitionHandle other) |
| | | 1170 | | { |
| | | 1171 | | return _rowId == other._rowId; |
| | | 1172 | | } |
| | | 1173 | | |
| | | 1174 | | public override int GetHashCode() |
| | | 1175 | | { |
| | | 1176 | | return _rowId.GetHashCode(); |
| | | 1177 | | } |
| | | 1178 | | |
| | | 1179 | | public static bool operator !=(PropertyDefinitionHandle left, PropertyDefinitionHandle right) |
| | | 1180 | | { |
| | | 1181 | | return left._rowId != right._rowId; |
| | | 1182 | | } |
| | | 1183 | | } |
| | | 1184 | | |
| | | 1185 | | public readonly struct StandaloneSignatureHandle : IEquatable<StandaloneSignatureHandle> |
| | | 1186 | | { |
| | | 1187 | | private const uint tokenType = TokenTypeIds.Signature; |
| | | 1188 | | private const byte tokenTypeSmall = (byte)HandleType.Signature; |
| | | 1189 | | private readonly int _rowId; |
| | | 1190 | | |
| | | 1191 | | private StandaloneSignatureHandle(int rowId) |
| | | 1192 | | { |
| | | 1193 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1194 | | _rowId = rowId; |
| | | 1195 | | } |
| | | 1196 | | |
| | | 1197 | | internal static StandaloneSignatureHandle FromRowId(int rowId) |
| | | 1198 | | { |
| | | 1199 | | return new StandaloneSignatureHandle(rowId); |
| | | 1200 | | } |
| | | 1201 | | |
| | | 1202 | | public static implicit operator Handle(StandaloneSignatureHandle handle) |
| | | 1203 | | { |
| | | 1204 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1205 | | } |
| | | 1206 | | |
| | | 1207 | | public static implicit operator EntityHandle(StandaloneSignatureHandle handle) |
| | | 1208 | | { |
| | | 1209 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1210 | | } |
| | | 1211 | | |
| | | 1212 | | public static explicit operator StandaloneSignatureHandle(Handle handle) |
| | | 1213 | | { |
| | | 1214 | | if (handle.VType != tokenTypeSmall) |
| | | 1215 | | { |
| | | 1216 | | Throw.InvalidCast(); |
| | | 1217 | | } |
| | | 1218 | | |
| | | 1219 | | return new StandaloneSignatureHandle(handle.RowId); |
| | | 1220 | | } |
| | | 1221 | | |
| | | 1222 | | public static explicit operator StandaloneSignatureHandle(EntityHandle handle) |
| | | 1223 | | { |
| | | 1224 | | if (handle.VType != tokenType) |
| | | 1225 | | { |
| | | 1226 | | Throw.InvalidCast(); |
| | | 1227 | | } |
| | | 1228 | | |
| | | 1229 | | return new StandaloneSignatureHandle(handle.RowId); |
| | | 1230 | | } |
| | | 1231 | | |
| | | 1232 | | public bool IsNil |
| | | 1233 | | { |
| | | 1234 | | get |
| | | 1235 | | { |
| | | 1236 | | return RowId == 0; |
| | | 1237 | | } |
| | | 1238 | | } |
| | | 1239 | | |
| | | 1240 | | internal int RowId { get { return _rowId; } } |
| | | 1241 | | |
| | | 1242 | | public static bool operator ==(StandaloneSignatureHandle left, StandaloneSignatureHandle right) |
| | | 1243 | | { |
| | | 1244 | | return left._rowId == right._rowId; |
| | | 1245 | | } |
| | | 1246 | | |
| | | 1247 | | public override bool Equals(object? obj) |
| | | 1248 | | { |
| | | 1249 | | return obj is StandaloneSignatureHandle && ((StandaloneSignatureHandle)obj)._rowId == _rowId; |
| | | 1250 | | } |
| | | 1251 | | |
| | | 1252 | | public bool Equals(StandaloneSignatureHandle other) |
| | | 1253 | | { |
| | | 1254 | | return _rowId == other._rowId; |
| | | 1255 | | } |
| | | 1256 | | |
| | | 1257 | | public override int GetHashCode() |
| | | 1258 | | { |
| | | 1259 | | return _rowId.GetHashCode(); |
| | | 1260 | | } |
| | | 1261 | | |
| | | 1262 | | public static bool operator !=(StandaloneSignatureHandle left, StandaloneSignatureHandle right) |
| | | 1263 | | { |
| | | 1264 | | return left._rowId != right._rowId; |
| | | 1265 | | } |
| | | 1266 | | } |
| | | 1267 | | |
| | | 1268 | | public readonly struct ParameterHandle : IEquatable<ParameterHandle> |
| | | 1269 | | { |
| | | 1270 | | private const uint tokenType = TokenTypeIds.ParamDef; |
| | | 1271 | | private const byte tokenTypeSmall = (byte)HandleType.ParamDef; |
| | | 1272 | | private readonly int _rowId; |
| | | 1273 | | |
| | | 1274 | | private ParameterHandle(int rowId) |
| | | 1275 | | { |
| | | 1276 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1277 | | _rowId = rowId; |
| | | 1278 | | } |
| | | 1279 | | |
| | | 1280 | | internal static ParameterHandle FromRowId(int rowId) |
| | | 1281 | | { |
| | | 1282 | | return new ParameterHandle(rowId); |
| | | 1283 | | } |
| | | 1284 | | |
| | | 1285 | | public static implicit operator Handle(ParameterHandle handle) |
| | | 1286 | | { |
| | | 1287 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1288 | | } |
| | | 1289 | | |
| | | 1290 | | public static implicit operator EntityHandle(ParameterHandle handle) |
| | | 1291 | | { |
| | | 1292 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1293 | | } |
| | | 1294 | | |
| | | 1295 | | public static explicit operator ParameterHandle(Handle handle) |
| | | 1296 | | { |
| | | 1297 | | if (handle.VType != tokenTypeSmall) |
| | | 1298 | | { |
| | | 1299 | | Throw.InvalidCast(); |
| | | 1300 | | } |
| | | 1301 | | |
| | | 1302 | | return new ParameterHandle(handle.RowId); |
| | | 1303 | | } |
| | | 1304 | | |
| | | 1305 | | public static explicit operator ParameterHandle(EntityHandle handle) |
| | | 1306 | | { |
| | | 1307 | | if (handle.VType != tokenType) |
| | | 1308 | | { |
| | | 1309 | | Throw.InvalidCast(); |
| | | 1310 | | } |
| | | 1311 | | |
| | | 1312 | | return new ParameterHandle(handle.RowId); |
| | | 1313 | | } |
| | | 1314 | | |
| | | 1315 | | public bool IsNil |
| | | 1316 | | { |
| | | 1317 | | get |
| | | 1318 | | { |
| | | 1319 | | return RowId == 0; |
| | | 1320 | | } |
| | | 1321 | | } |
| | | 1322 | | |
| | | 1323 | | internal int RowId { get { return _rowId; } } |
| | | 1324 | | |
| | | 1325 | | public static bool operator ==(ParameterHandle left, ParameterHandle right) |
| | | 1326 | | { |
| | | 1327 | | return left._rowId == right._rowId; |
| | | 1328 | | } |
| | | 1329 | | |
| | | 1330 | | public override bool Equals(object? obj) |
| | | 1331 | | { |
| | | 1332 | | return obj is ParameterHandle && ((ParameterHandle)obj)._rowId == _rowId; |
| | | 1333 | | } |
| | | 1334 | | |
| | | 1335 | | public bool Equals(ParameterHandle other) |
| | | 1336 | | { |
| | | 1337 | | return _rowId == other._rowId; |
| | | 1338 | | } |
| | | 1339 | | |
| | | 1340 | | public override int GetHashCode() |
| | | 1341 | | { |
| | | 1342 | | return _rowId.GetHashCode(); |
| | | 1343 | | } |
| | | 1344 | | |
| | | 1345 | | public static bool operator !=(ParameterHandle left, ParameterHandle right) |
| | | 1346 | | { |
| | | 1347 | | return left._rowId != right._rowId; |
| | | 1348 | | } |
| | | 1349 | | } |
| | | 1350 | | |
| | | 1351 | | public readonly struct GenericParameterHandle : IEquatable<GenericParameterHandle> |
| | | 1352 | | { |
| | | 1353 | | private const uint tokenType = TokenTypeIds.GenericParam; |
| | | 1354 | | private const byte tokenTypeSmall = (byte)HandleType.GenericParam; |
| | | 1355 | | private readonly int _rowId; |
| | | 1356 | | |
| | | 1357 | | private GenericParameterHandle(int rowId) |
| | | 1358 | | { |
| | | 1359 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1360 | | _rowId = rowId; |
| | | 1361 | | } |
| | | 1362 | | |
| | | 1363 | | internal static GenericParameterHandle FromRowId(int rowId) |
| | | 1364 | | { |
| | | 1365 | | return new GenericParameterHandle(rowId); |
| | | 1366 | | } |
| | | 1367 | | |
| | | 1368 | | public static implicit operator Handle(GenericParameterHandle handle) |
| | | 1369 | | { |
| | | 1370 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1371 | | } |
| | | 1372 | | |
| | | 1373 | | public static implicit operator EntityHandle(GenericParameterHandle handle) |
| | | 1374 | | { |
| | | 1375 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1376 | | } |
| | | 1377 | | |
| | | 1378 | | public static explicit operator GenericParameterHandle(Handle handle) |
| | | 1379 | | { |
| | | 1380 | | if (handle.VType != tokenTypeSmall) |
| | | 1381 | | { |
| | | 1382 | | Throw.InvalidCast(); |
| | | 1383 | | } |
| | | 1384 | | |
| | | 1385 | | return new GenericParameterHandle(handle.RowId); |
| | | 1386 | | } |
| | | 1387 | | |
| | | 1388 | | public static explicit operator GenericParameterHandle(EntityHandle handle) |
| | | 1389 | | { |
| | | 1390 | | if (handle.VType != tokenType) |
| | | 1391 | | { |
| | | 1392 | | Throw.InvalidCast(); |
| | | 1393 | | } |
| | | 1394 | | |
| | | 1395 | | return new GenericParameterHandle(handle.RowId); |
| | | 1396 | | } |
| | | 1397 | | |
| | | 1398 | | public bool IsNil |
| | | 1399 | | { |
| | | 1400 | | get |
| | | 1401 | | { |
| | | 1402 | | return RowId == 0; |
| | | 1403 | | } |
| | | 1404 | | } |
| | | 1405 | | |
| | | 1406 | | internal int RowId { get { return _rowId; } } |
| | | 1407 | | |
| | | 1408 | | public static bool operator ==(GenericParameterHandle left, GenericParameterHandle right) |
| | | 1409 | | { |
| | | 1410 | | return left._rowId == right._rowId; |
| | | 1411 | | } |
| | | 1412 | | |
| | | 1413 | | public override bool Equals(object? obj) |
| | | 1414 | | { |
| | | 1415 | | return obj is GenericParameterHandle && ((GenericParameterHandle)obj)._rowId == _rowId; |
| | | 1416 | | } |
| | | 1417 | | |
| | | 1418 | | public bool Equals(GenericParameterHandle other) |
| | | 1419 | | { |
| | | 1420 | | return _rowId == other._rowId; |
| | | 1421 | | } |
| | | 1422 | | |
| | | 1423 | | public override int GetHashCode() |
| | | 1424 | | { |
| | | 1425 | | return _rowId.GetHashCode(); |
| | | 1426 | | } |
| | | 1427 | | |
| | | 1428 | | public static bool operator !=(GenericParameterHandle left, GenericParameterHandle right) |
| | | 1429 | | { |
| | | 1430 | | return left._rowId != right._rowId; |
| | | 1431 | | } |
| | | 1432 | | } |
| | | 1433 | | |
| | | 1434 | | public readonly struct GenericParameterConstraintHandle : IEquatable<GenericParameterConstraintHandle> |
| | | 1435 | | { |
| | | 1436 | | private const uint tokenType = TokenTypeIds.GenericParamConstraint; |
| | | 1437 | | private const byte tokenTypeSmall = (byte)HandleType.GenericParamConstraint; |
| | | 1438 | | private readonly int _rowId; |
| | | 1439 | | |
| | | 1440 | | private GenericParameterConstraintHandle(int rowId) |
| | | 1441 | | { |
| | | 1442 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1443 | | _rowId = rowId; |
| | | 1444 | | } |
| | | 1445 | | |
| | | 1446 | | internal static GenericParameterConstraintHandle FromRowId(int rowId) |
| | | 1447 | | { |
| | | 1448 | | return new GenericParameterConstraintHandle(rowId); |
| | | 1449 | | } |
| | | 1450 | | |
| | | 1451 | | public static implicit operator Handle(GenericParameterConstraintHandle handle) |
| | | 1452 | | { |
| | | 1453 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1454 | | } |
| | | 1455 | | |
| | | 1456 | | public static implicit operator EntityHandle(GenericParameterConstraintHandle handle) |
| | | 1457 | | { |
| | | 1458 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1459 | | } |
| | | 1460 | | |
| | | 1461 | | public static explicit operator GenericParameterConstraintHandle(Handle handle) |
| | | 1462 | | { |
| | | 1463 | | if (handle.VType != tokenTypeSmall) |
| | | 1464 | | { |
| | | 1465 | | Throw.InvalidCast(); |
| | | 1466 | | } |
| | | 1467 | | |
| | | 1468 | | return new GenericParameterConstraintHandle(handle.RowId); |
| | | 1469 | | } |
| | | 1470 | | |
| | | 1471 | | public static explicit operator GenericParameterConstraintHandle(EntityHandle handle) |
| | | 1472 | | { |
| | | 1473 | | if (handle.VType != tokenType) |
| | | 1474 | | { |
| | | 1475 | | Throw.InvalidCast(); |
| | | 1476 | | } |
| | | 1477 | | |
| | | 1478 | | return new GenericParameterConstraintHandle(handle.RowId); |
| | | 1479 | | } |
| | | 1480 | | |
| | | 1481 | | public bool IsNil |
| | | 1482 | | { |
| | | 1483 | | get |
| | | 1484 | | { |
| | | 1485 | | return RowId == 0; |
| | | 1486 | | } |
| | | 1487 | | } |
| | | 1488 | | |
| | | 1489 | | internal int RowId { get { return _rowId; } } |
| | | 1490 | | |
| | | 1491 | | public static bool operator ==(GenericParameterConstraintHandle left, GenericParameterConstraintHandle right) |
| | | 1492 | | { |
| | | 1493 | | return left._rowId == right._rowId; |
| | | 1494 | | } |
| | | 1495 | | |
| | | 1496 | | public override bool Equals(object? obj) |
| | | 1497 | | { |
| | | 1498 | | return obj is GenericParameterConstraintHandle && ((GenericParameterConstraintHandle)obj)._rowId == _rowId; |
| | | 1499 | | } |
| | | 1500 | | |
| | | 1501 | | public bool Equals(GenericParameterConstraintHandle other) |
| | | 1502 | | { |
| | | 1503 | | return _rowId == other._rowId; |
| | | 1504 | | } |
| | | 1505 | | |
| | | 1506 | | public override int GetHashCode() |
| | | 1507 | | { |
| | | 1508 | | return _rowId.GetHashCode(); |
| | | 1509 | | } |
| | | 1510 | | |
| | | 1511 | | public static bool operator !=(GenericParameterConstraintHandle left, GenericParameterConstraintHandle right) |
| | | 1512 | | { |
| | | 1513 | | return left._rowId != right._rowId; |
| | | 1514 | | } |
| | | 1515 | | } |
| | | 1516 | | |
| | | 1517 | | public readonly struct ModuleReferenceHandle : IEquatable<ModuleReferenceHandle> |
| | | 1518 | | { |
| | | 1519 | | private const uint tokenType = TokenTypeIds.ModuleRef; |
| | | 1520 | | private const byte tokenTypeSmall = (byte)HandleType.ModuleRef; |
| | | 1521 | | private readonly int _rowId; |
| | | 1522 | | |
| | | 1523 | | private ModuleReferenceHandle(int rowId) |
| | | 1524 | | { |
| | | 1525 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1526 | | _rowId = rowId; |
| | | 1527 | | } |
| | | 1528 | | |
| | | 1529 | | internal static ModuleReferenceHandle FromRowId(int rowId) |
| | | 1530 | | { |
| | | 1531 | | return new ModuleReferenceHandle(rowId); |
| | | 1532 | | } |
| | | 1533 | | |
| | | 1534 | | public static implicit operator Handle(ModuleReferenceHandle handle) |
| | | 1535 | | { |
| | | 1536 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1537 | | } |
| | | 1538 | | |
| | | 1539 | | public static implicit operator EntityHandle(ModuleReferenceHandle handle) |
| | | 1540 | | { |
| | | 1541 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1542 | | } |
| | | 1543 | | |
| | | 1544 | | public static explicit operator ModuleReferenceHandle(Handle handle) |
| | | 1545 | | { |
| | | 1546 | | if (handle.VType != tokenTypeSmall) |
| | | 1547 | | { |
| | | 1548 | | Throw.InvalidCast(); |
| | | 1549 | | } |
| | | 1550 | | |
| | | 1551 | | return new ModuleReferenceHandle(handle.RowId); |
| | | 1552 | | } |
| | | 1553 | | |
| | | 1554 | | public static explicit operator ModuleReferenceHandle(EntityHandle handle) |
| | | 1555 | | { |
| | | 1556 | | if (handle.VType != tokenType) |
| | | 1557 | | { |
| | | 1558 | | Throw.InvalidCast(); |
| | | 1559 | | } |
| | | 1560 | | |
| | | 1561 | | return new ModuleReferenceHandle(handle.RowId); |
| | | 1562 | | } |
| | | 1563 | | |
| | | 1564 | | public bool IsNil |
| | | 1565 | | { |
| | | 1566 | | get |
| | | 1567 | | { |
| | | 1568 | | return RowId == 0; |
| | | 1569 | | } |
| | | 1570 | | } |
| | | 1571 | | |
| | | 1572 | | internal int RowId { get { return _rowId; } } |
| | | 1573 | | |
| | | 1574 | | public static bool operator ==(ModuleReferenceHandle left, ModuleReferenceHandle right) |
| | | 1575 | | { |
| | | 1576 | | return left._rowId == right._rowId; |
| | | 1577 | | } |
| | | 1578 | | |
| | | 1579 | | public override bool Equals(object? obj) |
| | | 1580 | | { |
| | | 1581 | | return obj is ModuleReferenceHandle && ((ModuleReferenceHandle)obj)._rowId == _rowId; |
| | | 1582 | | } |
| | | 1583 | | |
| | | 1584 | | public bool Equals(ModuleReferenceHandle other) |
| | | 1585 | | { |
| | | 1586 | | return _rowId == other._rowId; |
| | | 1587 | | } |
| | | 1588 | | |
| | | 1589 | | public override int GetHashCode() |
| | | 1590 | | { |
| | | 1591 | | return _rowId.GetHashCode(); |
| | | 1592 | | } |
| | | 1593 | | |
| | | 1594 | | public static bool operator !=(ModuleReferenceHandle left, ModuleReferenceHandle right) |
| | | 1595 | | { |
| | | 1596 | | return left._rowId != right._rowId; |
| | | 1597 | | } |
| | | 1598 | | } |
| | | 1599 | | |
| | | 1600 | | public readonly struct AssemblyReferenceHandle : IEquatable<AssemblyReferenceHandle> |
| | | 1601 | | { |
| | | 1602 | | private const uint tokenType = TokenTypeIds.AssemblyRef; |
| | | 1603 | | private const byte tokenTypeSmall = (byte)HandleType.AssemblyRef; |
| | | 1604 | | |
| | | 1605 | | // bits: |
| | | 1606 | | // 31: IsVirtual |
| | | 1607 | | // 24..30: 0 |
| | | 1608 | | // 0..23: Heap offset or Virtual index |
| | | 1609 | | private readonly uint _value; |
| | | 1610 | | |
| | | 1611 | | internal enum VirtualIndex |
| | | 1612 | | { |
| | | 1613 | | System_Runtime, |
| | | 1614 | | System_Runtime_InteropServices_WindowsRuntime, |
| | | 1615 | | System_ObjectModel, |
| | | 1616 | | System_Runtime_WindowsRuntime, |
| | | 1617 | | System_Runtime_WindowsRuntime_UI_Xaml, |
| | | 1618 | | System_Numerics_Vectors, |
| | | 1619 | | |
| | | 1620 | | Count |
| | | 1621 | | } |
| | | 1622 | | |
| | | 1623 | | private AssemblyReferenceHandle(uint value) |
| | | 1624 | | { |
| | | 1625 | | _value = value; |
| | | 1626 | | } |
| | | 1627 | | |
| | | 1628 | | internal static AssemblyReferenceHandle FromRowId(int rowId) |
| | | 1629 | | { |
| | | 1630 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1631 | | return new AssemblyReferenceHandle((uint)rowId); |
| | | 1632 | | } |
| | | 1633 | | |
| | | 1634 | | internal static AssemblyReferenceHandle FromVirtualIndex(VirtualIndex virtualIndex) |
| | | 1635 | | { |
| | | 1636 | | Debug.Assert(virtualIndex < VirtualIndex.Count); |
| | | 1637 | | return new AssemblyReferenceHandle(TokenTypeIds.VirtualBit | (uint)virtualIndex); |
| | | 1638 | | } |
| | | 1639 | | |
| | | 1640 | | public static implicit operator Handle(AssemblyReferenceHandle handle) |
| | | 1641 | | { |
| | | 1642 | | return Handle.FromVToken(handle.VToken); |
| | | 1643 | | } |
| | | 1644 | | |
| | | 1645 | | public static implicit operator EntityHandle(AssemblyReferenceHandle handle) |
| | | 1646 | | { |
| | | 1647 | | return new EntityHandle(handle.VToken); |
| | | 1648 | | } |
| | | 1649 | | |
| | | 1650 | | public static explicit operator AssemblyReferenceHandle(Handle handle) |
| | | 1651 | | { |
| | | 1652 | | if (handle.Type != tokenTypeSmall) |
| | | 1653 | | { |
| | | 1654 | | Throw.InvalidCast(); |
| | | 1655 | | } |
| | | 1656 | | |
| | | 1657 | | return new AssemblyReferenceHandle(handle.SpecificEntityHandleValue); |
| | | 1658 | | } |
| | | 1659 | | |
| | | 1660 | | public static explicit operator AssemblyReferenceHandle(EntityHandle handle) |
| | | 1661 | | { |
| | | 1662 | | if (handle.Type != tokenType) |
| | | 1663 | | { |
| | | 1664 | | Throw.InvalidCast(); |
| | | 1665 | | } |
| | | 1666 | | |
| | | 1667 | | return new AssemblyReferenceHandle(handle.SpecificHandleValue); |
| | | 1668 | | } |
| | | 1669 | | |
| | | 1670 | | internal uint Value |
| | | 1671 | | { |
| | | 1672 | | get { return _value; } |
| | | 1673 | | } |
| | | 1674 | | |
| | | 1675 | | private uint VToken |
| | | 1676 | | { |
| | | 1677 | | get { return _value | tokenType; } |
| | | 1678 | | } |
| | | 1679 | | |
| | | 1680 | | public bool IsNil |
| | | 1681 | | { |
| | | 1682 | | get { return _value == 0; } |
| | | 1683 | | } |
| | | 1684 | | |
| | | 1685 | | internal bool IsVirtual |
| | | 1686 | | { |
| | | 1687 | | get { return (_value & TokenTypeIds.VirtualBit) != 0; } |
| | | 1688 | | } |
| | | 1689 | | |
| | | 1690 | | internal int RowId { get { return (int)(_value & TokenTypeIds.RIDMask); } } |
| | | 1691 | | |
| | | 1692 | | public static bool operator ==(AssemblyReferenceHandle left, AssemblyReferenceHandle right) |
| | | 1693 | | { |
| | | 1694 | | return left._value == right._value; |
| | | 1695 | | } |
| | | 1696 | | |
| | | 1697 | | public override bool Equals(object? obj) |
| | | 1698 | | { |
| | | 1699 | | return obj is AssemblyReferenceHandle && ((AssemblyReferenceHandle)obj)._value == _value; |
| | | 1700 | | } |
| | | 1701 | | |
| | | 1702 | | public bool Equals(AssemblyReferenceHandle other) |
| | | 1703 | | { |
| | | 1704 | | return _value == other._value; |
| | | 1705 | | } |
| | | 1706 | | |
| | | 1707 | | public override int GetHashCode() |
| | | 1708 | | { |
| | | 1709 | | return _value.GetHashCode(); |
| | | 1710 | | } |
| | | 1711 | | |
| | | 1712 | | public static bool operator !=(AssemblyReferenceHandle left, AssemblyReferenceHandle right) |
| | | 1713 | | { |
| | | 1714 | | return left._value != right._value; |
| | | 1715 | | } |
| | | 1716 | | } |
| | | 1717 | | |
| | | 1718 | | public readonly struct CustomAttributeHandle : IEquatable<CustomAttributeHandle> |
| | | 1719 | | { |
| | | 1720 | | private const uint tokenType = TokenTypeIds.CustomAttribute; |
| | | 1721 | | private const byte tokenTypeSmall = (byte)HandleType.CustomAttribute; |
| | | 1722 | | private readonly int _rowId; |
| | | 1723 | | |
| | | 1724 | | private CustomAttributeHandle(int rowId) |
| | | 1725 | | { |
| | | 1726 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1727 | | _rowId = rowId; |
| | | 1728 | | } |
| | | 1729 | | |
| | | 1730 | | internal static CustomAttributeHandle FromRowId(int rowId) |
| | | 1731 | | { |
| | | 1732 | | return new CustomAttributeHandle(rowId); |
| | | 1733 | | } |
| | | 1734 | | |
| | | 1735 | | public static implicit operator Handle(CustomAttributeHandle handle) |
| | | 1736 | | { |
| | | 1737 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1738 | | } |
| | | 1739 | | |
| | | 1740 | | public static implicit operator EntityHandle(CustomAttributeHandle handle) |
| | | 1741 | | { |
| | | 1742 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1743 | | } |
| | | 1744 | | |
| | | 1745 | | public static explicit operator CustomAttributeHandle(Handle handle) |
| | | 1746 | | { |
| | | 1747 | | if (handle.VType != tokenTypeSmall) |
| | | 1748 | | { |
| | | 1749 | | Throw.InvalidCast(); |
| | | 1750 | | } |
| | | 1751 | | |
| | | 1752 | | return new CustomAttributeHandle(handle.RowId); |
| | | 1753 | | } |
| | | 1754 | | |
| | | 1755 | | public static explicit operator CustomAttributeHandle(EntityHandle handle) |
| | | 1756 | | { |
| | | 1757 | | if (handle.VType != tokenType) |
| | | 1758 | | { |
| | | 1759 | | Throw.InvalidCast(); |
| | | 1760 | | } |
| | | 1761 | | |
| | | 1762 | | return new CustomAttributeHandle(handle.RowId); |
| | | 1763 | | } |
| | | 1764 | | |
| | | 1765 | | public bool IsNil |
| | | 1766 | | { |
| | | 1767 | | get |
| | | 1768 | | { |
| | | 1769 | | return _rowId == 0; |
| | | 1770 | | } |
| | | 1771 | | } |
| | | 1772 | | |
| | | 1773 | | internal int RowId { get { return _rowId; } } |
| | | 1774 | | |
| | | 1775 | | public static bool operator ==(CustomAttributeHandle left, CustomAttributeHandle right) |
| | | 1776 | | { |
| | | 1777 | | return left._rowId == right._rowId; |
| | | 1778 | | } |
| | | 1779 | | |
| | | 1780 | | public override bool Equals(object? obj) |
| | | 1781 | | { |
| | | 1782 | | return obj is CustomAttributeHandle && ((CustomAttributeHandle)obj)._rowId == _rowId; |
| | | 1783 | | } |
| | | 1784 | | |
| | | 1785 | | public bool Equals(CustomAttributeHandle other) |
| | | 1786 | | { |
| | | 1787 | | return _rowId == other._rowId; |
| | | 1788 | | } |
| | | 1789 | | |
| | | 1790 | | public override int GetHashCode() |
| | | 1791 | | { |
| | | 1792 | | return _rowId.GetHashCode(); |
| | | 1793 | | } |
| | | 1794 | | |
| | | 1795 | | public static bool operator !=(CustomAttributeHandle left, CustomAttributeHandle right) |
| | | 1796 | | { |
| | | 1797 | | return left._rowId != right._rowId; |
| | | 1798 | | } |
| | | 1799 | | } |
| | | 1800 | | |
| | | 1801 | | public readonly struct DeclarativeSecurityAttributeHandle : IEquatable<DeclarativeSecurityAttributeHandle> |
| | | 1802 | | { |
| | | 1803 | | private const uint tokenType = TokenTypeIds.DeclSecurity; |
| | | 1804 | | private const byte tokenTypeSmall = (byte)HandleType.DeclSecurity; |
| | | 1805 | | private readonly int _rowId; |
| | | 1806 | | |
| | | 1807 | | private DeclarativeSecurityAttributeHandle(int rowId) |
| | | 1808 | | { |
| | | 1809 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1810 | | _rowId = rowId; |
| | | 1811 | | } |
| | | 1812 | | |
| | | 1813 | | internal static DeclarativeSecurityAttributeHandle FromRowId(int rowId) |
| | | 1814 | | { |
| | | 1815 | | return new DeclarativeSecurityAttributeHandle(rowId); |
| | | 1816 | | } |
| | | 1817 | | |
| | | 1818 | | public static implicit operator Handle(DeclarativeSecurityAttributeHandle handle) |
| | | 1819 | | { |
| | | 1820 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1821 | | } |
| | | 1822 | | |
| | | 1823 | | public static implicit operator EntityHandle(DeclarativeSecurityAttributeHandle handle) |
| | | 1824 | | { |
| | | 1825 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1826 | | } |
| | | 1827 | | |
| | | 1828 | | public static explicit operator DeclarativeSecurityAttributeHandle(Handle handle) |
| | | 1829 | | { |
| | | 1830 | | if (handle.VType != tokenTypeSmall) |
| | | 1831 | | { |
| | | 1832 | | Throw.InvalidCast(); |
| | | 1833 | | } |
| | | 1834 | | |
| | | 1835 | | return new DeclarativeSecurityAttributeHandle(handle.RowId); |
| | | 1836 | | } |
| | | 1837 | | |
| | | 1838 | | public static explicit operator DeclarativeSecurityAttributeHandle(EntityHandle handle) |
| | | 1839 | | { |
| | | 1840 | | if (handle.VType != tokenType) |
| | | 1841 | | { |
| | | 1842 | | Throw.InvalidCast(); |
| | | 1843 | | } |
| | | 1844 | | |
| | | 1845 | | return new DeclarativeSecurityAttributeHandle(handle.RowId); |
| | | 1846 | | } |
| | | 1847 | | |
| | | 1848 | | public bool IsNil |
| | | 1849 | | { |
| | | 1850 | | get |
| | | 1851 | | { |
| | | 1852 | | return _rowId == 0; |
| | | 1853 | | } |
| | | 1854 | | } |
| | | 1855 | | |
| | | 1856 | | internal int RowId { get { return _rowId; } } |
| | | 1857 | | |
| | | 1858 | | public static bool operator ==(DeclarativeSecurityAttributeHandle left, DeclarativeSecurityAttributeHandle right |
| | | 1859 | | { |
| | | 1860 | | return left._rowId == right._rowId; |
| | | 1861 | | } |
| | | 1862 | | |
| | | 1863 | | public override bool Equals(object? obj) |
| | | 1864 | | { |
| | | 1865 | | return obj is DeclarativeSecurityAttributeHandle && ((DeclarativeSecurityAttributeHandle)obj)._rowId == _row |
| | | 1866 | | } |
| | | 1867 | | |
| | | 1868 | | public bool Equals(DeclarativeSecurityAttributeHandle other) |
| | | 1869 | | { |
| | | 1870 | | return _rowId == other._rowId; |
| | | 1871 | | } |
| | | 1872 | | |
| | | 1873 | | public override int GetHashCode() |
| | | 1874 | | { |
| | | 1875 | | return _rowId.GetHashCode(); |
| | | 1876 | | } |
| | | 1877 | | |
| | | 1878 | | public static bool operator !=(DeclarativeSecurityAttributeHandle left, DeclarativeSecurityAttributeHandle right |
| | | 1879 | | { |
| | | 1880 | | return left._rowId != right._rowId; |
| | | 1881 | | } |
| | | 1882 | | } |
| | | 1883 | | |
| | | 1884 | | public readonly struct ConstantHandle : IEquatable<ConstantHandle> |
| | | 1885 | | { |
| | | 1886 | | private const uint tokenType = TokenTypeIds.Constant; |
| | | 1887 | | private const byte tokenTypeSmall = (byte)HandleType.Constant; |
| | | 1888 | | private readonly int _rowId; |
| | | 1889 | | |
| | | 1890 | | private ConstantHandle(int rowId) |
| | | 1891 | | { |
| | | 1892 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1893 | | _rowId = rowId; |
| | | 1894 | | } |
| | | 1895 | | |
| | | 1896 | | internal static ConstantHandle FromRowId(int rowId) |
| | | 1897 | | { |
| | | 1898 | | return new ConstantHandle(rowId); |
| | | 1899 | | } |
| | | 1900 | | |
| | | 1901 | | public static implicit operator Handle(ConstantHandle handle) |
| | | 1902 | | { |
| | | 1903 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1904 | | } |
| | | 1905 | | |
| | | 1906 | | public static implicit operator EntityHandle(ConstantHandle handle) |
| | | 1907 | | { |
| | | 1908 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1909 | | } |
| | | 1910 | | |
| | | 1911 | | public static explicit operator ConstantHandle(Handle handle) |
| | | 1912 | | { |
| | | 1913 | | if (handle.VType != tokenTypeSmall) |
| | | 1914 | | { |
| | | 1915 | | Throw.InvalidCast(); |
| | | 1916 | | } |
| | | 1917 | | |
| | | 1918 | | return new ConstantHandle(handle.RowId); |
| | | 1919 | | } |
| | | 1920 | | |
| | | 1921 | | public static explicit operator ConstantHandle(EntityHandle handle) |
| | | 1922 | | { |
| | | 1923 | | if (handle.VType != tokenType) |
| | | 1924 | | { |
| | | 1925 | | Throw.InvalidCast(); |
| | | 1926 | | } |
| | | 1927 | | |
| | | 1928 | | return new ConstantHandle(handle.RowId); |
| | | 1929 | | } |
| | | 1930 | | |
| | | 1931 | | public bool IsNil |
| | | 1932 | | { |
| | | 1933 | | get |
| | | 1934 | | { |
| | | 1935 | | return RowId == 0; |
| | | 1936 | | } |
| | | 1937 | | } |
| | | 1938 | | |
| | | 1939 | | internal int RowId { get { return _rowId; } } |
| | | 1940 | | |
| | | 1941 | | public static bool operator ==(ConstantHandle left, ConstantHandle right) |
| | | 1942 | | { |
| | | 1943 | | return left._rowId == right._rowId; |
| | | 1944 | | } |
| | | 1945 | | |
| | | 1946 | | public override bool Equals(object? obj) |
| | | 1947 | | { |
| | | 1948 | | return obj is ConstantHandle && ((ConstantHandle)obj)._rowId == _rowId; |
| | | 1949 | | } |
| | | 1950 | | |
| | | 1951 | | public bool Equals(ConstantHandle other) |
| | | 1952 | | { |
| | | 1953 | | return _rowId == other._rowId; |
| | | 1954 | | } |
| | | 1955 | | |
| | | 1956 | | public override int GetHashCode() |
| | | 1957 | | { |
| | | 1958 | | return _rowId.GetHashCode(); |
| | | 1959 | | } |
| | | 1960 | | |
| | | 1961 | | public static bool operator !=(ConstantHandle left, ConstantHandle right) |
| | | 1962 | | { |
| | | 1963 | | return left._rowId != right._rowId; |
| | | 1964 | | } |
| | | 1965 | | } |
| | | 1966 | | |
| | | 1967 | | public readonly struct ManifestResourceHandle : IEquatable<ManifestResourceHandle> |
| | | 1968 | | { |
| | | 1969 | | private const uint tokenType = TokenTypeIds.ManifestResource; |
| | | 1970 | | private const byte tokenTypeSmall = (byte)HandleType.ManifestResource; |
| | | 1971 | | private readonly int _rowId; |
| | | 1972 | | |
| | | 1973 | | private ManifestResourceHandle(int rowId) |
| | | 1974 | | { |
| | | 1975 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 1976 | | _rowId = rowId; |
| | | 1977 | | } |
| | | 1978 | | |
| | | 1979 | | internal static ManifestResourceHandle FromRowId(int rowId) |
| | | 1980 | | { |
| | | 1981 | | return new ManifestResourceHandle(rowId); |
| | | 1982 | | } |
| | | 1983 | | |
| | | 1984 | | public static implicit operator Handle(ManifestResourceHandle handle) |
| | | 1985 | | { |
| | | 1986 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 1987 | | } |
| | | 1988 | | |
| | | 1989 | | public static implicit operator EntityHandle(ManifestResourceHandle handle) |
| | | 1990 | | { |
| | | 1991 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 1992 | | } |
| | | 1993 | | |
| | | 1994 | | public static explicit operator ManifestResourceHandle(Handle handle) |
| | | 1995 | | { |
| | | 1996 | | if (handle.VType != tokenTypeSmall) |
| | | 1997 | | { |
| | | 1998 | | Throw.InvalidCast(); |
| | | 1999 | | } |
| | | 2000 | | |
| | | 2001 | | return new ManifestResourceHandle(handle.RowId); |
| | | 2002 | | } |
| | | 2003 | | |
| | | 2004 | | public static explicit operator ManifestResourceHandle(EntityHandle handle) |
| | | 2005 | | { |
| | | 2006 | | if (handle.VType != tokenType) |
| | | 2007 | | { |
| | | 2008 | | Throw.InvalidCast(); |
| | | 2009 | | } |
| | | 2010 | | |
| | | 2011 | | return new ManifestResourceHandle(handle.RowId); |
| | | 2012 | | } |
| | | 2013 | | |
| | | 2014 | | public bool IsNil |
| | | 2015 | | { |
| | | 2016 | | get |
| | | 2017 | | { |
| | | 2018 | | return RowId == 0; |
| | | 2019 | | } |
| | | 2020 | | } |
| | | 2021 | | |
| | | 2022 | | internal int RowId { get { return _rowId; } } |
| | | 2023 | | |
| | | 2024 | | public static bool operator ==(ManifestResourceHandle left, ManifestResourceHandle right) |
| | | 2025 | | { |
| | | 2026 | | return left._rowId == right._rowId; |
| | | 2027 | | } |
| | | 2028 | | |
| | | 2029 | | public override bool Equals(object? obj) |
| | | 2030 | | { |
| | | 2031 | | return obj is ManifestResourceHandle && ((ManifestResourceHandle)obj)._rowId == _rowId; |
| | | 2032 | | } |
| | | 2033 | | |
| | | 2034 | | public bool Equals(ManifestResourceHandle other) |
| | | 2035 | | { |
| | | 2036 | | return _rowId == other._rowId; |
| | | 2037 | | } |
| | | 2038 | | |
| | | 2039 | | public override int GetHashCode() |
| | | 2040 | | { |
| | | 2041 | | return _rowId.GetHashCode(); |
| | | 2042 | | } |
| | | 2043 | | |
| | | 2044 | | public static bool operator !=(ManifestResourceHandle left, ManifestResourceHandle right) |
| | | 2045 | | { |
| | | 2046 | | return left._rowId != right._rowId; |
| | | 2047 | | } |
| | | 2048 | | } |
| | | 2049 | | |
| | | 2050 | | public readonly struct AssemblyFileHandle : IEquatable<AssemblyFileHandle> |
| | | 2051 | | { |
| | | 2052 | | private const uint tokenType = TokenTypeIds.File; |
| | | 2053 | | private const byte tokenTypeSmall = (byte)HandleType.File; |
| | | 2054 | | private readonly int _rowId; |
| | | 2055 | | |
| | | 2056 | | private AssemblyFileHandle(int rowId) |
| | | 2057 | | { |
| | | 2058 | | Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); |
| | | 2059 | | _rowId = rowId; |
| | | 2060 | | } |
| | | 2061 | | |
| | | 2062 | | internal static AssemblyFileHandle FromRowId(int rowId) |
| | | 2063 | | { |
| | | 2064 | | return new AssemblyFileHandle(rowId); |
| | | 2065 | | } |
| | | 2066 | | |
| | | 2067 | | public static implicit operator Handle(AssemblyFileHandle handle) |
| | | 2068 | | { |
| | | 2069 | | return new Handle(tokenTypeSmall, handle._rowId); |
| | | 2070 | | } |
| | | 2071 | | |
| | | 2072 | | public static implicit operator EntityHandle(AssemblyFileHandle handle) |
| | | 2073 | | { |
| | | 2074 | | return new EntityHandle((uint)(tokenType | handle._rowId)); |
| | | 2075 | | } |
| | | 2076 | | |
| | | 2077 | | public static explicit operator AssemblyFileHandle(Handle handle) |
| | | 2078 | | { |
| | | 2079 | | if (handle.VType != tokenTypeSmall) |
| | | 2080 | | { |
| | | 2081 | | Throw.InvalidCast(); |
| | | 2082 | | } |
| | | 2083 | | |
| | | 2084 | | return new AssemblyFileHandle(handle.RowId); |
| | | 2085 | | } |
| | | 2086 | | |
| | | 2087 | | public static explicit operator AssemblyFileHandle(EntityHandle handle) |
| | | 2088 | | { |
| | | 2089 | | if (handle.VType != tokenType) |
| | | 2090 | | { |
| | | 2091 | | Throw.InvalidCast(); |
| | | 2092 | | } |
| | | 2093 | | |
| | | 2094 | | return new AssemblyFileHandle(handle.RowId); |
| | | 2095 | | } |
| | | 2096 | | |
| | | 2097 | | public bool IsNil |
| | | 2098 | | { |
| | | 2099 | | get |
| | | 2100 | | { |
| | | 2101 | | return RowId == 0; |
| | | 2102 | | } |
| | | 2103 | | } |
| | | 2104 | | |
| | | 2105 | | internal int RowId { get { return _rowId; } } |
| | | 2106 | | |
| | | 2107 | | public static bool operator ==(AssemblyFileHandle left, AssemblyFileHandle right) |
| | | 2108 | | { |
| | | 2109 | | return left._rowId == right._rowId; |
| | | 2110 | | } |
| | | 2111 | | |
| | | 2112 | | public override bool Equals(object? obj) |
| | | 2113 | | { |
| | | 2114 | | return obj is AssemblyFileHandle && ((AssemblyFileHandle)obj)._rowId == _rowId; |
| | | 2115 | | } |
| | | 2116 | | |
| | | 2117 | | public bool Equals(AssemblyFileHandle other) |
| | | 2118 | | { |
| | | 2119 | | return _rowId == other._rowId; |
| | | 2120 | | } |
| | | 2121 | | |
| | | 2122 | | public override int GetHashCode() |
| | | 2123 | | { |
| | | 2124 | | return _rowId.GetHashCode(); |
| | | 2125 | | } |
| | | 2126 | | |
| | | 2127 | | public static bool operator !=(AssemblyFileHandle left, AssemblyFileHandle right) |
| | | 2128 | | { |
| | | 2129 | | return left._rowId != right._rowId; |
| | | 2130 | | } |
| | | 2131 | | } |
| | | 2132 | | |
| | | 2133 | | /// <summary> |
| | | 2134 | | /// #UserString heap handle. |
| | | 2135 | | /// </summary> |
| | | 2136 | | /// <remarks> |
| | | 2137 | | /// The handle is 32-bit wide. |
| | | 2138 | | /// </remarks> |
| | | 2139 | | public readonly struct UserStringHandle : IEquatable<UserStringHandle> |
| | | 2140 | | { |
| | | 2141 | | // bits: |
| | | 2142 | | // 31: 0 |
| | | 2143 | | // 24..30: 0 |
| | | 2144 | | // 0..23: index |
| | | 2145 | | private readonly int _offset; |
| | | 2146 | | |
| | | 2147 | | private UserStringHandle(int offset) |
| | | 2148 | | { |
| | | 2149 | | // #US string indices must fit into 24bits since they are used in IL stream tokens |
| | | 2150 | | Debug.Assert((offset & 0xFF000000) == 0); |
| | | 2151 | | _offset = offset; |
| | | 2152 | | } |
| | | 2153 | | |
| | | 2154 | | internal static UserStringHandle FromOffset(int heapOffset) |
| | | 2155 | | { |
| | | 2156 | | return new UserStringHandle(heapOffset); |
| | | 2157 | | } |
| | | 2158 | | |
| | | 2159 | | public static implicit operator Handle(UserStringHandle handle) |
| | | 2160 | | { |
| | | 2161 | | return new Handle((byte)HandleType.UserString, handle._offset); |
| | | 2162 | | } |
| | | 2163 | | |
| | | 2164 | | public static explicit operator UserStringHandle(Handle handle) |
| | | 2165 | | { |
| | | 2166 | | if (handle.VType != HandleType.UserString) |
| | | 2167 | | { |
| | | 2168 | | Throw.InvalidCast(); |
| | | 2169 | | } |
| | | 2170 | | |
| | | 2171 | | return new UserStringHandle(handle.Offset); |
| | | 2172 | | } |
| | | 2173 | | |
| | | 2174 | | public bool IsNil |
| | | 2175 | | { |
| | | 2176 | | get { return _offset == 0; } |
| | | 2177 | | } |
| | | 2178 | | |
| | | 2179 | | internal int GetHeapOffset() |
| | | 2180 | | { |
| | | 2181 | | return _offset; |
| | | 2182 | | } |
| | | 2183 | | |
| | | 2184 | | public static bool operator ==(UserStringHandle left, UserStringHandle right) |
| | | 2185 | | { |
| | | 2186 | | return left._offset == right._offset; |
| | | 2187 | | } |
| | | 2188 | | |
| | | 2189 | | public override bool Equals(object? obj) |
| | | 2190 | | { |
| | | 2191 | | return obj is UserStringHandle && ((UserStringHandle)obj)._offset == _offset; |
| | | 2192 | | } |
| | | 2193 | | |
| | | 2194 | | public bool Equals(UserStringHandle other) |
| | | 2195 | | { |
| | | 2196 | | return _offset == other._offset; |
| | | 2197 | | } |
| | | 2198 | | |
| | | 2199 | | public override int GetHashCode() |
| | | 2200 | | { |
| | | 2201 | | return _offset.GetHashCode(); |
| | | 2202 | | } |
| | | 2203 | | |
| | | 2204 | | public static bool operator !=(UserStringHandle left, UserStringHandle right) |
| | | 2205 | | { |
| | | 2206 | | return left._offset != right._offset; |
| | | 2207 | | } |
| | | 2208 | | } |
| | | 2209 | | |
| | | 2210 | | // #String heap handle |
| | | 2211 | | public readonly struct StringHandle : IEquatable<StringHandle> |
| | | 2212 | | { |
| | | 2213 | | // bits: |
| | | 2214 | | // 31: IsVirtual |
| | | 2215 | | // 29..31: type (non-virtual: String, DotTerminatedString; virtual: VirtualString, WinRTPrefixedString) |
| | | 2216 | | // 0..28: Heap offset or Virtual index |
| | | 2217 | | private readonly uint _value; |
| | | 2218 | | |
| | | 2219 | | internal enum VirtualIndex |
| | | 2220 | | { |
| | | 2221 | | System_Runtime_WindowsRuntime, |
| | | 2222 | | System_Runtime, |
| | | 2223 | | System_ObjectModel, |
| | | 2224 | | System_Runtime_WindowsRuntime_UI_Xaml, |
| | | 2225 | | System_Runtime_InteropServices_WindowsRuntime, |
| | | 2226 | | System_Numerics_Vectors, |
| | | 2227 | | |
| | | 2228 | | Dispose, |
| | | 2229 | | |
| | | 2230 | | AttributeTargets, |
| | | 2231 | | AttributeUsageAttribute, |
| | | 2232 | | Color, |
| | | 2233 | | CornerRadius, |
| | | 2234 | | DateTimeOffset, |
| | | 2235 | | Duration, |
| | | 2236 | | DurationType, |
| | | 2237 | | EventHandler1, |
| | | 2238 | | EventRegistrationToken, |
| | | 2239 | | Exception, |
| | | 2240 | | GeneratorPosition, |
| | | 2241 | | GridLength, |
| | | 2242 | | GridUnitType, |
| | | 2243 | | ICommand, |
| | | 2244 | | IDictionary2, |
| | | 2245 | | IDisposable, |
| | | 2246 | | IEnumerable, |
| | | 2247 | | IEnumerable1, |
| | | 2248 | | IList, |
| | | 2249 | | IList1, |
| | | 2250 | | INotifyCollectionChanged, |
| | | 2251 | | INotifyPropertyChanged, |
| | | 2252 | | IReadOnlyDictionary2, |
| | | 2253 | | IReadOnlyList1, |
| | | 2254 | | KeyTime, |
| | | 2255 | | KeyValuePair2, |
| | | 2256 | | Matrix, |
| | | 2257 | | Matrix3D, |
| | | 2258 | | Matrix3x2, |
| | | 2259 | | Matrix4x4, |
| | | 2260 | | NotifyCollectionChangedAction, |
| | | 2261 | | NotifyCollectionChangedEventArgs, |
| | | 2262 | | NotifyCollectionChangedEventHandler, |
| | | 2263 | | Nullable1, |
| | | 2264 | | Plane, |
| | | 2265 | | Point, |
| | | 2266 | | PropertyChangedEventArgs, |
| | | 2267 | | PropertyChangedEventHandler, |
| | | 2268 | | Quaternion, |
| | | 2269 | | Rect, |
| | | 2270 | | RepeatBehavior, |
| | | 2271 | | RepeatBehaviorType, |
| | | 2272 | | Size, |
| | | 2273 | | System, |
| | | 2274 | | System_Collections, |
| | | 2275 | | System_Collections_Generic, |
| | | 2276 | | System_Collections_Specialized, |
| | | 2277 | | System_ComponentModel, |
| | | 2278 | | System_Numerics, |
| | | 2279 | | System_Windows_Input, |
| | | 2280 | | Thickness, |
| | | 2281 | | TimeSpan, |
| | | 2282 | | Type, |
| | | 2283 | | Uri, |
| | | 2284 | | Vector2, |
| | | 2285 | | Vector3, |
| | | 2286 | | Vector4, |
| | | 2287 | | Windows_Foundation, |
| | | 2288 | | Windows_UI, |
| | | 2289 | | Windows_UI_Xaml, |
| | | 2290 | | Windows_UI_Xaml_Controls_Primitives, |
| | | 2291 | | Windows_UI_Xaml_Media, |
| | | 2292 | | Windows_UI_Xaml_Media_Animation, |
| | | 2293 | | Windows_UI_Xaml_Media_Media3D, |
| | | 2294 | | |
| | | 2295 | | Count |
| | | 2296 | | } |
| | | 2297 | | |
| | | 2298 | | private StringHandle(uint value) |
| | | 2299 | | { |
| | | 2300 | | Debug.Assert((value & StringHandleType.TypeMask) == StringHandleType.String || |
| | | 2301 | | (value & StringHandleType.TypeMask) == StringHandleType.VirtualString || |
| | | 2302 | | (value & StringHandleType.TypeMask) == StringHandleType.WinRTPrefixedString || |
| | | 2303 | | (value & StringHandleType.TypeMask) == StringHandleType.DotTerminatedString); |
| | | 2304 | | |
| | | 2305 | | _value = value; |
| | | 2306 | | } |
| | | 2307 | | |
| | | 2308 | | internal static StringHandle FromOffset(int heapOffset) |
| | | 2309 | | { |
| | | 2310 | | return new StringHandle(StringHandleType.String | (uint)heapOffset); |
| | | 2311 | | } |
| | | 2312 | | |
| | | 2313 | | internal static StringHandle FromVirtualIndex(VirtualIndex virtualIndex) |
| | | 2314 | | { |
| | | 2315 | | Debug.Assert(virtualIndex < VirtualIndex.Count); |
| | | 2316 | | return new StringHandle(StringHandleType.VirtualString | (uint)virtualIndex); |
| | | 2317 | | } |
| | | 2318 | | |
| | | 2319 | | internal static StringHandle FromWriterVirtualIndex(int virtualIndex) |
| | | 2320 | | { |
| | | 2321 | | return new StringHandle(StringHandleType.VirtualString | (uint)virtualIndex); |
| | | 2322 | | } |
| | | 2323 | | |
| | | 2324 | | internal StringHandle WithWinRTPrefix() |
| | | 2325 | | { |
| | | 2326 | | Debug.Assert(StringKind == StringKind.Plain); |
| | | 2327 | | return new StringHandle(StringHandleType.WinRTPrefixedString | _value); |
| | | 2328 | | } |
| | | 2329 | | |
| | | 2330 | | internal StringHandle WithDotTermination() |
| | | 2331 | | { |
| | | 2332 | | Debug.Assert(StringKind == StringKind.Plain); |
| | | 2333 | | return new StringHandle(StringHandleType.DotTerminatedString | _value); |
| | | 2334 | | } |
| | | 2335 | | |
| | | 2336 | | internal StringHandle SuffixRaw(int prefixByteLength) |
| | | 2337 | | { |
| | | 2338 | | Debug.Assert(StringKind == StringKind.Plain); |
| | | 2339 | | Debug.Assert(prefixByteLength >= 0); |
| | | 2340 | | return new StringHandle(StringHandleType.String | (_value + (uint)prefixByteLength)); |
| | | 2341 | | } |
| | | 2342 | | |
| | | 2343 | | public static implicit operator Handle(StringHandle handle) |
| | | 2344 | | { |
| | | 2345 | | // VTTx xxxx xxxx xxxx xxxx xxxx xxxx xxxx -> V111 10TT |
| | | 2346 | | return new Handle( |
| | | 2347 | | (byte)((handle._value & HeapHandleType.VirtualBit) >> 24 | HandleType.String | (handle._value & StringHa |
| | | 2348 | | (int)(handle._value & HeapHandleType.OffsetMask)); |
| | | 2349 | | } |
| | | 2350 | | |
| | | 2351 | | public static explicit operator StringHandle(Handle handle) |
| | | 2352 | | { |
| | | 2353 | | if ((handle.VType & ~(HandleType.VirtualBit | HandleType.NonVirtualStringTypeMask)) != HandleType.String) |
| | | 2354 | | { |
| | | 2355 | | Throw.InvalidCast(); |
| | | 2356 | | } |
| | | 2357 | | |
| | | 2358 | | // V111 10TT -> VTTx xxxx xxxx xxxx xxxx xxxx xxxx xxxx |
| | | 2359 | | return new StringHandle( |
| | | 2360 | | (handle.VType & HandleType.VirtualBit) << 24 | |
| | | 2361 | | (handle.VType & HandleType.NonVirtualStringTypeMask) << HeapHandleType.OffsetBitCount | |
| | | 2362 | | (uint)handle.Offset); |
| | | 2363 | | } |
| | | 2364 | | |
| | | 2365 | | internal uint RawValue => _value; |
| | | 2366 | | |
| | | 2367 | | internal bool IsVirtual |
| | | 2368 | | { |
| | | 2369 | | get { return (_value & HeapHandleType.VirtualBit) != 0; } |
| | | 2370 | | } |
| | | 2371 | | |
| | | 2372 | | public bool IsNil |
| | | 2373 | | { |
| | | 2374 | | get |
| | | 2375 | | { |
| | | 2376 | | // virtual strings are never nil, so include virtual bit |
| | | 2377 | | return (_value & (HeapHandleType.VirtualBit | HeapHandleType.OffsetMask)) == 0; |
| | | 2378 | | } |
| | | 2379 | | } |
| | | 2380 | | |
| | | 2381 | | internal int GetHeapOffset() |
| | | 2382 | | { |
| | | 2383 | | // WinRT prefixed strings are virtual, the value is a heap offset |
| | | 2384 | | Debug.Assert(!IsVirtual || StringKind == StringKind.WinRTPrefixed); |
| | | 2385 | | return (int)(_value & HeapHandleType.OffsetMask); |
| | | 2386 | | } |
| | | 2387 | | |
| | | 2388 | | internal VirtualIndex GetVirtualIndex() |
| | | 2389 | | { |
| | | 2390 | | Debug.Assert(IsVirtual && StringKind != StringKind.WinRTPrefixed); |
| | | 2391 | | return (VirtualIndex)(_value & HeapHandleType.OffsetMask); |
| | | 2392 | | } |
| | | 2393 | | |
| | | 2394 | | internal int GetWriterVirtualIndex() |
| | | 2395 | | { |
| | | 2396 | | Debug.Assert(IsNil || IsVirtual && StringKind == StringKind.Virtual); |
| | | 2397 | | return (int)(_value & HeapHandleType.OffsetMask); |
| | | 2398 | | } |
| | | 2399 | | |
| | | 2400 | | internal StringKind StringKind |
| | | 2401 | | { |
| | | 2402 | | get { return (StringKind)(_value >> HeapHandleType.OffsetBitCount); } |
| | | 2403 | | } |
| | | 2404 | | |
| | | 2405 | | public override bool Equals(object? obj) |
| | | 2406 | | { |
| | | 2407 | | return obj is StringHandle && Equals((StringHandle)obj); |
| | | 2408 | | } |
| | | 2409 | | |
| | | 2410 | | public bool Equals(StringHandle other) |
| | | 2411 | | { |
| | | 2412 | | return _value == other._value; |
| | | 2413 | | } |
| | | 2414 | | |
| | | 2415 | | public override int GetHashCode() |
| | | 2416 | | { |
| | | 2417 | | return unchecked((int)_value); |
| | | 2418 | | } |
| | | 2419 | | |
| | | 2420 | | public static bool operator ==(StringHandle left, StringHandle right) |
| | | 2421 | | { |
| | | 2422 | | return left.Equals(right); |
| | | 2423 | | } |
| | | 2424 | | |
| | | 2425 | | public static bool operator !=(StringHandle left, StringHandle right) |
| | | 2426 | | { |
| | | 2427 | | return !left.Equals(right); |
| | | 2428 | | } |
| | | 2429 | | } |
| | | 2430 | | |
| | | 2431 | | /// <summary> |
| | | 2432 | | /// A handle that represents a namespace definition. |
| | | 2433 | | /// </summary> |
| | | 2434 | | public readonly struct NamespaceDefinitionHandle : IEquatable<NamespaceDefinitionHandle> |
| | | 2435 | | { |
| | | 2436 | | // Non-virtual (namespace having at least one type or forwarder of its own) |
| | | 2437 | | // heap offset is to the null-terminated full name of the namespace in the |
| | | 2438 | | // #String heap. |
| | | 2439 | | // |
| | | 2440 | | // Virtual (namespace having child namespaces but no types of its own) |
| | | 2441 | | // the virtual index is an auto-incremented value and serves solely to |
| | | 2442 | | // create unique values for indexing into the NamespaceCache. |
| | | 2443 | | |
| | | 2444 | | // bits: |
| | | 2445 | | // 31: IsVirtual |
| | | 2446 | | // 29..31: 0 |
| | | 2447 | | // 0..28: Heap offset or Virtual index |
| | | 2448 | | private readonly uint _value; |
| | | 2449 | | |
| | | 2450 | | private NamespaceDefinitionHandle(uint value) |
| | | 2451 | | { |
| | | 2452 | | _value = value; |
| | | 2453 | | } |
| | | 2454 | | |
| | | 2455 | | internal static NamespaceDefinitionHandle FromFullNameOffset(int stringHeapOffset) |
| | | 2456 | | { |
| | | 2457 | | return new NamespaceDefinitionHandle((uint)stringHeapOffset); |
| | | 2458 | | } |
| | | 2459 | | |
| | | 2460 | | internal static NamespaceDefinitionHandle FromVirtualIndex(uint virtualIndex) |
| | | 2461 | | { |
| | | 2462 | | // we arbitrarily disallow 0 virtual index to simplify nil check. |
| | | 2463 | | Debug.Assert(virtualIndex != 0); |
| | | 2464 | | |
| | | 2465 | | if (!HeapHandleType.IsValidHeapOffset(virtualIndex)) |
| | | 2466 | | { |
| | | 2467 | | // only a pathological assembly would hit this, but it must fit in 29 bits. |
| | | 2468 | | Throw.TooManySubnamespaces(); |
| | | 2469 | | } |
| | | 2470 | | |
| | | 2471 | | return new NamespaceDefinitionHandle(TokenTypeIds.VirtualBit | virtualIndex); |
| | | 2472 | | } |
| | | 2473 | | |
| | | 2474 | | public static implicit operator Handle(NamespaceDefinitionHandle handle) |
| | | 2475 | | { |
| | | 2476 | | return new Handle( |
| | | 2477 | | (byte)((handle._value & HeapHandleType.VirtualBit) >> 24 | HandleType.Namespace), |
| | | 2478 | | (int)(handle._value & HeapHandleType.OffsetMask)); |
| | | 2479 | | } |
| | | 2480 | | |
| | | 2481 | | public static explicit operator NamespaceDefinitionHandle(Handle handle) |
| | | 2482 | | { |
| | | 2483 | | if ((handle.VType & HandleType.TypeMask) != HandleType.Namespace) |
| | | 2484 | | { |
| | | 2485 | | Throw.InvalidCast(); |
| | | 2486 | | } |
| | | 2487 | | |
| | | 2488 | | return new NamespaceDefinitionHandle( |
| | | 2489 | | (handle.VType & HandleType.VirtualBit) << TokenTypeIds.RowIdBitCount | |
| | | 2490 | | (uint)handle.Offset); |
| | | 2491 | | } |
| | | 2492 | | |
| | | 2493 | | public bool IsNil |
| | | 2494 | | { |
| | | 2495 | | get |
| | | 2496 | | { |
| | | 2497 | | return _value == 0; |
| | | 2498 | | } |
| | | 2499 | | } |
| | | 2500 | | |
| | | 2501 | | internal bool IsVirtual |
| | | 2502 | | { |
| | | 2503 | | get { return (_value & HeapHandleType.VirtualBit) != 0; } |
| | | 2504 | | } |
| | | 2505 | | |
| | | 2506 | | internal int GetHeapOffset() |
| | | 2507 | | { |
| | | 2508 | | Debug.Assert(!IsVirtual); |
| | | 2509 | | return (int)(_value & HeapHandleType.OffsetMask); |
| | | 2510 | | } |
| | | 2511 | | |
| | | 2512 | | internal bool HasFullName |
| | | 2513 | | { |
| | | 2514 | | get { return !IsVirtual; } |
| | | 2515 | | } |
| | | 2516 | | |
| | | 2517 | | internal StringHandle GetFullName() |
| | | 2518 | | { |
| | | 2519 | | Debug.Assert(HasFullName); |
| | | 2520 | | return StringHandle.FromOffset(GetHeapOffset()); |
| | | 2521 | | } |
| | | 2522 | | |
| | | 2523 | | public override bool Equals([NotNullWhen(true)] object? obj) |
| | | 2524 | | { |
| | | 2525 | | return obj is NamespaceDefinitionHandle ndh && Equals(ndh); |
| | | 2526 | | } |
| | | 2527 | | |
| | | 2528 | | public bool Equals(NamespaceDefinitionHandle other) |
| | | 2529 | | { |
| | | 2530 | | return _value == other._value; |
| | | 2531 | | } |
| | | 2532 | | |
| | | 2533 | | public override int GetHashCode() |
| | | 2534 | | { |
| | | 2535 | | return unchecked((int)_value); |
| | | 2536 | | } |
| | | 2537 | | |
| | | 2538 | | public static bool operator ==(NamespaceDefinitionHandle left, NamespaceDefinitionHandle right) |
| | | 2539 | | { |
| | | 2540 | | return left.Equals(right); |
| | | 2541 | | } |
| | | 2542 | | |
| | | 2543 | | public static bool operator !=(NamespaceDefinitionHandle left, NamespaceDefinitionHandle right) |
| | | 2544 | | { |
| | | 2545 | | return !left.Equals(right); |
| | | 2546 | | } |
| | | 2547 | | } |
| | | 2548 | | |
| | | 2549 | | // #Blob heap handle |
| | | 2550 | | public readonly struct BlobHandle : IEquatable<BlobHandle> |
| | | 2551 | | { |
| | | 2552 | | // bits: |
| | | 2553 | | // 31: IsVirtual |
| | | 2554 | | // 29..30: 0 |
| | | 2555 | | // 0..28: Heap offset or Virtual Value (16 bits) + Virtual Index (8 bits) |
| | | 2556 | | private readonly uint _value; |
| | | 2557 | | |
| | | 2558 | | internal enum VirtualIndex : byte |
| | | 2559 | | { |
| | | 2560 | | Nil, |
| | | 2561 | | |
| | | 2562 | | // B0 3F 5F 7F 11 D5 0A 3A |
| | | 2563 | | ContractPublicKeyToken, |
| | | 2564 | | |
| | | 2565 | | // 00, 24, 00, 00, 04, ... |
| | | 2566 | | ContractPublicKey, |
| | | 2567 | | |
| | | 2568 | | // Template for projected AttributeUsage attribute blob |
| | | 2569 | | AttributeUsage_AllowSingle, |
| | | 2570 | | |
| | | 2571 | | // Template for projected AttributeUsage attribute blob with AllowMultiple=true |
| | | 2572 | | AttributeUsage_AllowMultiple, |
| | | 2573 | | |
| | | 2574 | | Count |
| | | 2575 | | } |
| | | 2576 | | |
| | | 2577 | | private BlobHandle(uint value) |
| | | 2578 | | { |
| | | 2579 | | _value = value; |
| | | 2580 | | } |
| | | 2581 | | |
| | | 2582 | | internal static BlobHandle FromOffset(int heapOffset) |
| | | 2583 | | { |
| | | 2584 | | return new BlobHandle((uint)heapOffset); |
| | | 2585 | | } |
| | | 2586 | | |
| | | 2587 | | internal static BlobHandle FromVirtualIndex(VirtualIndex virtualIndex, ushort virtualValue) |
| | | 2588 | | { |
| | | 2589 | | Debug.Assert(virtualIndex < VirtualIndex.Count); |
| | | 2590 | | return new BlobHandle(TokenTypeIds.VirtualBit | (uint)(virtualValue << 8) | (uint)virtualIndex); |
| | | 2591 | | } |
| | | 2592 | | |
| | | 2593 | | internal const int TemplateParameterOffset_AttributeUsageTarget = 2; |
| | | 2594 | | |
| | | 2595 | | internal void SubstituteTemplateParameters(byte[] blob) |
| | | 2596 | | { |
| | | 2597 | | Debug.Assert(blob.Length >= TemplateParameterOffset_AttributeUsageTarget + 4); |
| | | 2598 | | |
| | | 2599 | | BinaryPrimitives.WriteUInt32LittleEndian(blob.AsSpan(TemplateParameterOffset_AttributeUsageTarget), VirtualV |
| | | 2600 | | } |
| | | 2601 | | |
| | | 2602 | | public static implicit operator Handle(BlobHandle handle) |
| | | 2603 | | { |
| | | 2604 | | // V... -> V111 0001 |
| | | 2605 | | return new Handle( |
| | | 2606 | | (byte)((handle._value & HeapHandleType.VirtualBit) >> 24 | HandleType.Blob), |
| | | 2607 | | (int)(handle._value & HeapHandleType.OffsetMask)); |
| | | 2608 | | } |
| | | 2609 | | |
| | | 2610 | | public static explicit operator BlobHandle(Handle handle) |
| | | 2611 | | { |
| | | 2612 | | if ((handle.VType & HandleType.TypeMask) != HandleType.Blob) |
| | | 2613 | | { |
| | | 2614 | | Throw.InvalidCast(); |
| | | 2615 | | } |
| | | 2616 | | |
| | | 2617 | | return new BlobHandle( |
| | | 2618 | | (handle.VType & HandleType.VirtualBit) << TokenTypeIds.RowIdBitCount | |
| | | 2619 | | (uint)handle.Offset); |
| | | 2620 | | } |
| | | 2621 | | |
| | | 2622 | | internal uint RawValue => _value; |
| | | 2623 | | |
| | | 2624 | | public bool IsNil |
| | | 2625 | | { |
| | | 2626 | | get { return _value == 0; } |
| | | 2627 | | } |
| | | 2628 | | |
| | | 2629 | | internal int GetHeapOffset() |
| | | 2630 | | { |
| | | 2631 | | Debug.Assert(!IsVirtual); |
| | | 2632 | | return (int)_value; |
| | | 2633 | | } |
| | | 2634 | | |
| | | 2635 | | internal VirtualIndex GetVirtualIndex() |
| | | 2636 | | { |
| | | 2637 | | Debug.Assert(IsVirtual); |
| | | 2638 | | return (VirtualIndex)(_value & 0xff); |
| | | 2639 | | } |
| | | 2640 | | |
| | | 2641 | | internal bool IsVirtual |
| | | 2642 | | { |
| | | 2643 | | get { return (_value & TokenTypeIds.VirtualBit) != 0; } |
| | | 2644 | | } |
| | | 2645 | | |
| | | 2646 | | private ushort VirtualValue |
| | | 2647 | | { |
| | | 2648 | | get { return unchecked((ushort)(_value >> 8)); } |
| | | 2649 | | } |
| | | 2650 | | |
| | | 2651 | | public override bool Equals([NotNullWhen(true)] object? obj) |
| | | 2652 | | { |
| | | 2653 | | return obj is BlobHandle bh && Equals(bh); |
| | | 2654 | | } |
| | | 2655 | | |
| | | 2656 | | public bool Equals(BlobHandle other) |
| | | 2657 | | { |
| | | 2658 | | return _value == other._value; |
| | | 2659 | | } |
| | | 2660 | | |
| | | 2661 | | public override int GetHashCode() |
| | | 2662 | | { |
| | | 2663 | | return unchecked((int)_value); |
| | | 2664 | | } |
| | | 2665 | | |
| | | 2666 | | public static bool operator ==(BlobHandle left, BlobHandle right) |
| | | 2667 | | { |
| | | 2668 | | return left.Equals(right); |
| | | 2669 | | } |
| | | 2670 | | |
| | | 2671 | | public static bool operator !=(BlobHandle left, BlobHandle right) |
| | | 2672 | | { |
| | | 2673 | | return !left.Equals(right); |
| | | 2674 | | } |
| | | 2675 | | } |
| | | 2676 | | |
| | | 2677 | | // #Guid heap handle |
| | | 2678 | | public readonly struct GuidHandle : IEquatable<GuidHandle> |
| | | 2679 | | { |
| | | 2680 | | // The Guid heap is an array of GUIDs, each 16 bytes wide. |
| | | 2681 | | // Its first element is numbered 1, its second 2, and so on. |
| | | 2682 | | private readonly int _index; |
| | | 2683 | | |
| | | 2684 | | private GuidHandle(int index) |
| | | 2685 | | { |
| | | 2686 | | _index = index; |
| | | 2687 | | } |
| | | 2688 | | |
| | | 2689 | | internal static GuidHandle FromIndex(int heapIndex) |
| | | 2690 | | { |
| | | 2691 | | return new GuidHandle(heapIndex); |
| | | 2692 | | } |
| | | 2693 | | |
| | | 2694 | | public static implicit operator Handle(GuidHandle handle) |
| | | 2695 | | { |
| | | 2696 | | return new Handle((byte)HandleType.Guid, handle._index); |
| | | 2697 | | } |
| | | 2698 | | |
| | | 2699 | | public static explicit operator GuidHandle(Handle handle) |
| | | 2700 | | { |
| | | 2701 | | if (handle.VType != HandleType.Guid) |
| | | 2702 | | { |
| | | 2703 | | Throw.InvalidCast(); |
| | | 2704 | | } |
| | | 2705 | | |
| | | 2706 | | return new GuidHandle(handle.Offset); |
| | | 2707 | | } |
| | | 2708 | | |
| | | 2709 | | public bool IsNil |
| | | 2710 | | { |
| | | 2711 | | get { return _index == 0; } |
| | | 2712 | | } |
| | | 2713 | | |
| | | 2714 | | internal int Index |
| | | 2715 | | { |
| | | 2716 | | get { return _index; } |
| | | 2717 | | } |
| | | 2718 | | |
| | | 2719 | | public override bool Equals([NotNullWhen(true)] object? obj) |
| | | 2720 | | { |
| | | 2721 | | return obj is GuidHandle gh && Equals(gh); |
| | | 2722 | | } |
| | | 2723 | | |
| | | 2724 | | public bool Equals(GuidHandle other) |
| | | 2725 | | { |
| | | 2726 | | return _index == other._index; |
| | | 2727 | | } |
| | | 2728 | | |
| | | 2729 | | public override int GetHashCode() |
| | | 2730 | | { |
| | | 2731 | | return _index; |
| | | 2732 | | } |
| | | 2733 | | |
| | | 2734 | | public static bool operator ==(GuidHandle left, GuidHandle right) |
| | | 2735 | | { |
| | | 2736 | | return left.Equals(right); |
| | | 2737 | | } |
| | | 2738 | | |
| | | 2739 | | public static bool operator !=(GuidHandle left, GuidHandle right) |
| | | 2740 | | { |
| | | 2741 | | return !left.Equals(right); |
| | | 2742 | | } |
| | | 2743 | | } |
| | | 2744 | | } |
| | | 2745 | | |