| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Reflection; |
| | 4 | | using ZeroC.Slice.Internal; |
| | 5 | |
|
| | 6 | | namespace ZeroC.Slice; |
| | 7 | |
|
| | 8 | | /// <summary>Provides methods that create class and exception instances from Slice type IDs.</summary> |
| | 9 | | /// <remarks>When decoding a Slice1-encoded buffer, a Slice decoder uses its activator to create a class or exception |
| | 10 | | /// instance before decoding the instance's fields.</remarks> |
| | 11 | | /// <seealso cref="SliceDecoder" /> |
| | 12 | | public interface IActivator |
| | 13 | | { |
| | 14 | | /// <summary>Gets or creates an activator for the Slice types in the specified assembly and its referenced |
| | 15 | | /// assemblies.</summary> |
| | 16 | | /// <param name="assembly">The assembly.</param> |
| | 17 | | /// <returns>An activator that activates the Slice types defined in <paramref name="assembly" /> provided this |
| | 18 | | /// assembly contains generated code (as determined by the presence of the <see cref="SliceAttribute" /> attribute). |
| | 19 | | /// The Slice types defined in assemblies referenced by <paramref name="assembly" /> are included as well, |
| | 20 | | /// recursively. If a referenced assembly contains no generated code, the assemblies it references are not examined. |
| | 21 | | /// </returns> |
| 98 | 22 | | public static IActivator FromAssembly(Assembly assembly) => ActivatorFactory.Instance.Get(assembly); |
| | 23 | |
|
| | 24 | | /// <summary>Gets or creates an activator for the Slice types defined in the specified assemblies and their |
| | 25 | | /// referenced assemblies.</summary> |
| | 26 | | /// <param name="assemblies">The assemblies.</param> |
| | 27 | | /// <returns>An activator that activates the Slice types defined in <paramref name="assemblies" /> and their |
| | 28 | | /// referenced assemblies. See <see cref="FromAssembly(Assembly)" />.</returns> |
| | 29 | | public static IActivator FromAssemblies(params Assembly[] assemblies) => |
| 4 | 30 | | Internal.Activator.Merge(assemblies.Select(ActivatorFactory.Instance.Get)); |
| | 31 | |
|
| | 32 | | /// <summary>Creates an instance of a Slice class or Slice exception based on a type ID.</summary> |
| | 33 | | /// <param name="typeId">The Slice type ID.</param> |
| | 34 | | /// <returns>A new instance of the class identified by <paramref name="typeId" />, or null if the implementation |
| | 35 | | /// cannot find the corresponding C# class.</returns> |
| | 36 | | /// <remarks>This implementation of this method can also throw an exception if the class is found but the activation |
| | 37 | | /// of an instance fails.</remarks> |
| | 38 | | object? CreateInstance(string typeId); |
| | 39 | | } |