| | | 1 | | |
| | | 2 | | using System.Management.Automation; |
| | | 3 | | using System.Reflection; |
| | | 4 | | using Kestrun.Scripting; |
| | | 5 | | |
| | | 6 | | namespace Kestrun.Hosting.Options; |
| | | 7 | | /// <summary> |
| | | 8 | | /// Base options for specifying script code and language settings. |
| | | 9 | | /// </summary> |
| | | 10 | | public record LanguageOptions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// The script code to execute for this route. |
| | | 14 | | /// </summary> |
| | 182 | 15 | | public string? Code { get; set; } |
| | | 16 | | /// <summary> |
| | | 17 | | /// The scripting language used for the route's code. |
| | | 18 | | /// </summary> |
| | 378 | 19 | | public ScriptLanguage Language { get; set; } = ScriptLanguage.PowerShell; |
| | | 20 | | /// <summary> |
| | | 21 | | /// Additional import namespaces required for the script code. |
| | | 22 | | /// </summary> |
| | 53 | 23 | | public string[]? ExtraImports { get; set; } |
| | | 24 | | /// <summary> |
| | | 25 | | /// Additional assembly references required for the script code. |
| | | 26 | | /// </summary> |
| | 53 | 27 | | public Assembly[]? ExtraRefs { get; set; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// The script block created from the <see cref="Code"/> property, or null if no code is set. |
| | | 31 | | /// </summary> |
| | | 32 | | public ScriptBlock? ScriptBlock |
| | | 33 | | { |
| | 6 | 34 | | get => string.IsNullOrWhiteSpace(Code) ? null : ScriptBlock.Create(Code); |
| | | 35 | | set |
| | | 36 | | { |
| | 2 | 37 | | if (value is null) |
| | | 38 | | { |
| | 1 | 39 | | Code = null; |
| | 1 | 40 | | return; |
| | | 41 | | } |
| | 1 | 42 | | Code = value.ToString(); |
| | 1 | 43 | | Language = ScriptLanguage.PowerShell; |
| | 1 | 44 | | } |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Additional metadata for the route, represented as key-value pairs. |
| | | 49 | | /// </summary> |
| | 230 | 50 | | public Dictionary<string, object?>? Arguments { get; set; } = new Dictionary<string, object?>(StringComparer.Ordinal |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Version of the C# language to use when <see cref="Language"/> is <see cref="ScriptLanguage.CSharp"/>. |
| | | 54 | | /// </summary> |
| | 167 | 55 | | public Microsoft.CodeAnalysis.CSharp.LanguageVersion LanguageVersion { get; set; } = Microsoft.CodeAnalysis.CSharp.L |
| | | 56 | | } |