| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | namespace ZeroC.Slice; |
| | 4 | |
|
| | 5 | | /// <summary>Provides an extension method for <see cref="SliceDecoder" /> to decode a <c>WellKnownTypes::Uri</c> into a |
| | 6 | | /// <see cref="Uri" />.</summary> |
| | 7 | | public static class UriSliceDecoderExtensions |
| | 8 | | { |
| | 9 | | /// <summary>Decodes a URI.</summary> |
| | 10 | | /// <param name="decoder">The Slice decoder.</param> |
| | 11 | | /// <returns>The URI decoded as a <see cref="Uri"/>.</returns> |
| | 12 | | public static Uri DecodeUri(this ref SliceDecoder decoder) |
| 30 | 13 | | { |
| 30 | 14 | | string value = decoder.DecodeString(); |
| | 15 | | try |
| 30 | 16 | | { |
| 30 | 17 | | return new Uri(value, UriKind.RelativeOrAbsolute); |
| | 18 | | } |
| 0 | 19 | | catch (UriFormatException exception) |
| 0 | 20 | | { |
| 0 | 21 | | throw new InvalidDataException(message: null, exception); |
| | 22 | | } |
| 30 | 23 | | } |
| | 24 | | } |