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