|
| 1 | +//----------------------------------------------------------------------------- |
| 2 | +// <copyright file="IDecoder.cs" company="Dropbox Inc"> |
| 3 | +// Copyright (c) Dropbox Inc. All rights reserved. |
| 4 | +// </copyright> |
| 5 | +//----------------------------------------------------------------------------- |
| 6 | + |
| 7 | +namespace Dropbox.Api.Babel |
| 8 | +{ |
| 9 | + using System; |
| 10 | + using System.Collections.Generic; |
| 11 | + |
| 12 | + /// <summary> |
| 13 | + /// Interface that is used to decode objects that implement the |
| 14 | + /// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/> interface. |
| 15 | + /// </summary> |
| 16 | + public interface IDecoder |
| 17 | + { |
| 18 | + /// <summary> |
| 19 | + /// Used to get the name of the current union. |
| 20 | + /// </summary> |
| 21 | + /// <returns>The union name</returns> |
| 22 | + string GetUnionName(); |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Gets a context for the current object, the context object is used to access |
| 26 | + /// individual fields. |
| 27 | + /// </summary> |
| 28 | + /// <returns>The decoder context for the current object.</returns> |
| 29 | + IDecoderContext GetObject(); |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Sets the current source for this instance. |
| 33 | + /// </summary> |
| 34 | + /// <param name="source">The source as a string.</param> |
| 35 | + void SetSource(string source); |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Sets the current source for this instance. |
| 39 | + /// </summary> |
| 40 | + /// <param name="source">The source as a byte array.</param> |
| 41 | + void SetSource(byte[] source); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// A context used to get decoded field values from an encoded object. |
| 46 | + /// </summary> |
| 47 | + public interface IDecoderContext : IDisposable |
| 48 | + { |
| 49 | + /// <summary> |
| 50 | + /// Indicates whether the specified field is present in the object. |
| 51 | + /// </summary> |
| 52 | + /// <param name="name">The name of the field to check.</param> |
| 53 | + /// <returns><c>true</c> if the field is present; <c>false</c> otherwise.</returns> |
| 54 | + bool HasField(string name); |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Gets the value of a field. |
| 58 | + /// </summary> |
| 59 | + /// <typeparam name="T">The expected type of the field.</typeparam> |
| 60 | + /// <param name="name">The name of the field to get.</param> |
| 61 | + /// <returns>The decoded value of the field.</returns> |
| 62 | + T GetField<T>(string name); |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Gets the value of a field which is an object. |
| 66 | + /// </summary> |
| 67 | + /// <typeparam name="T">The expected type of the object. This must implement the |
| 68 | + /// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/> interface.</typeparam> |
| 69 | + /// <param name="name">The name of the field to get.</param> |
| 70 | + /// <returns>The decoded value of the field.</returns> |
| 71 | + T GetFieldObject<T>(string name) where T : IEncodable<T>, new(); |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// Gets the value of a field which is a list. |
| 75 | + /// </summary> |
| 76 | + /// <typeparam name="T">The expected type of the list elements.</typeparam> |
| 77 | + /// <param name="name">The name of the field.</param> |
| 78 | + /// <returns>The decoded list of items.</returns> |
| 79 | + IEnumerable<T> GetFieldList<T>(string name); |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Gets the value of a field which is a list of objects that implement |
| 83 | + /// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/>. |
| 84 | + /// </summary> |
| 85 | + /// <typeparam name="T">The expected type of the list elements.</typeparam> |
| 86 | + /// <param name="name">The name of the fields.</param> |
| 87 | + /// <returns>The decoded list of items.</returns> |
| 88 | + IEnumerable<T> GetFieldObjectList<T>(string name) where T : IEncodable<T>, new(); |
| 89 | + } |
| 90 | +} |
0 commit comments