| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | #nullable enable |
| | 4 | |
|
| | 5 | | namespace Ice; |
| | 6 | |
|
| | 7 | | /// <summary>Provides extension methods for <see cref="Type" />.</summary> |
| | 8 | | // Corresponds to IceRPC's ZeroC.Slice.TypeExtensions. |
| | 9 | | public static class TypeExtensions |
| | 10 | | { |
| | 11 | | /// <summary>Retrieves the Slice type ID from a type with the attribute <see cref="SliceTypeIdAttribute"/>. |
| | 12 | | /// </summary> |
| | 13 | | /// <param name="type">The type of a class or interface generated by the Slice compiler.</param> |
| | 14 | | /// <returns>The Slice type ID, or <see langword="null" /> if <paramref name="type" /> does not carry the |
| | 15 | | /// <see cref="SliceTypeIdAttribute"/> attribute. |
| | 16 | | /// </returns> |
| | 17 | | public static string? GetSliceTypeId(this Type type) |
| | 18 | | { |
| 1 | 19 | | object[] attributes = type.GetCustomAttributes(typeof(SliceTypeIdAttribute), false); |
| 1 | 20 | | return attributes.Length == 1 && attributes[0] is SliceTypeIdAttribute typeId ? typeId.Value : null; |
| | 21 | | } |
| | 22 | |
|
| | 23 | | /// <summary>Retrieves the compact Slice type ID from a type with the attribute |
| | 24 | | /// <see cref="CompactSliceTypeIdAttribute"/>.</summary> |
| | 25 | | /// <param name="type">The type of a class generated by the Slice compiler.</param> |
| | 26 | | /// <returns>The compact Slice type ID, or <see langword="null" /> if <paramref name="type" /> does not carry the |
| | 27 | | /// <see cref="CompactSliceTypeIdAttribute"/> attribute.</returns> |
| | 28 | | public static int? GetCompactSliceTypeId(this Type type) |
| | 29 | | { |
| 1 | 30 | | object[] attributes = type.GetCustomAttributes(typeof(CompactSliceTypeIdAttribute), false); |
| 1 | 31 | | return attributes.Length == 1 && attributes[0] is CompactSliceTypeIdAttribute typeId ? typeId.Value : null; |
| | 32 | | } |
| | 33 | | } |