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