Repository navigation
Expand file tree
/
Copy pathScriptingApiExportAttribute.cs
More file actions
88 lines (81 loc) · 2.75 KB
/
Copy pathScriptingApiExportAttribute.cs
File metadata and controls
88 lines (81 loc) · 2.75 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
namespace Inno.Scripting.Api;
/// <summary>
/// Exports one public runtime type to a script compilation profile.
/// </summary>
/// <remarks>
/// The declaration assembly does not need to own the exported type. Feature projects may expose
/// selected types from lower-level dependencies while the generated runtime reference preserves
/// the exported type's original assembly identity.
/// </remarks>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class ScriptingApiExportAttribute : Attribute
{
/// <summary>
/// Creates an explicit script API export.
/// </summary>
/// <param name="type">
/// The runtime type exposed to scripts.
/// </param>
/// <param name="scope">
/// The script profile that receives the type.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="type"/> is <see langword="null"/>.
/// </exception>
public ScriptingApiExportAttribute(
Type type,
ScriptingApiScope scope
)
: this(type, GetDefaultName(type), scope)
{
}
/// <summary>
/// Creates an explicit script API export with a script-facing type name.
/// </summary>
/// <param name="type">
/// The runtime type exposed to scripts.
/// </param>
/// <param name="name">
/// The type name presented by the script facade.
/// </param>
/// <param name="scope">
/// The script profile that receives the type.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="type"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when <paramref name="name"/> is empty.
/// </exception>
public ScriptingApiExportAttribute(
Type type,
string name,
ScriptingApiScope scope
) {
this.type = type ?? throw new ArgumentNullException(nameof(type));
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("A script-facing type name is required.", nameof(name));
this.name = name;
this.scope = scope;
}
/// <summary>
/// Gets the runtime type exposed to scripts.
/// </summary>
public Type type { get; }
/// <summary>
/// Gets the type name presented by the script facade.
/// </summary>
public string name { get; }
/// <summary>
/// Gets the script profile that receives the type.
/// </summary>
public ScriptingApiScope scope { get; }
private static string GetDefaultName(Type? type)
{
if (type is null)
return string.Empty;
int aritySeparator = type.Name.IndexOf('`');
return aritySeparator < 0 ? type.Name : type.Name[..aritySeparator];
}
}