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