initial scaffolding for programmatic scripting support (e.g. via XML)

This commit is contained in:
Michael Becker 2020-12-04 23:43:10 -05:00
parent 78a3b73cf6
commit c275c25d0a
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
6 changed files with 122 additions and 0 deletions

View File

@ -86,6 +86,11 @@
<Compile Include="CommandItem.cs" />
<Compile Include="StockType.cs" />
<Compile Include="ContextChangedEvent.cs" />
<Compile Include="Scripting\Strings\ScriptableString.cs" />
<Compile Include="Scripting\Strings\StringComponent.cs" />
<Compile Include="Scripting\Strings\StringComponents\ConditionalStringComponent.cs" />
<Compile Include="Scripting\Strings\StringComponents\LiteralStringComponent.cs" />
<Compile Include="Scripting\ScriptEnvironment.cs" />
<Compile Include="Collections\Generic\ExtensionMethods.cs" />
</ItemGroup>
<ItemGroup>
@ -93,6 +98,8 @@
<Folder Include="Logic\Expressions\" />
<Folder Include="Logic\Conditional\" />
<Folder Include="IO\" />
<Folder Include="Scripting\" />
<Folder Include="Scripting\Strings\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,8 @@
using System;
namespace MBS.Framework.Scripting
{
public class ScriptEnvironment
{
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Text;
namespace MBS.Framework.Scripting.Strings
{
public class ScriptableString : ICloneable
{
public ScriptableString(StringComponent[] components = null)
{
if (components != null)
{
for (int i = 0; i < components.Length; i++)
{
Components.Add(components[i]);
}
}
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < Components.Count; i++)
{
sb.Append(Components[i].ToString());
if (i < Components.Count - 1)
sb.Append(' ');
}
return sb.ToString();
}
public string ToString(ScriptEnvironment environment)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < Components.Count; i++)
{
sb.Append(Components[i].ToString(environment));
if (i < Components.Count - 1)
sb.Append(' ');
}
return sb.ToString();
}
public StringComponent.StringComponentCollection Components { get; } = new StringComponent.StringComponentCollection();
public object Clone()
{
ScriptableString clone = new ScriptableString();
for (int i = 0; i < Components.Count; i++)
{
clone.Components.Add(Components[i].Clone() as StringComponent);
}
return clone;
}
}
}

View File

@ -0,0 +1,16 @@
using System;
namespace MBS.Framework.Scripting.Strings
{
public abstract class StringComponent : ICloneable
{
public class StringComponentCollection
: System.Collections.ObjectModel.Collection<StringComponent>
{
}
public abstract string ToString(ScriptEnvironment environment);
public abstract object Clone();
}
}

View File

@ -0,0 +1,10 @@
using System;
using MBS.Framework.Logic.Conditional;
namespace MBS.Framework.Scripting.Strings.StringComponents
{
public class ConditionalStringComponent
{
public IConditionalStatement Condition { get; }
}
}

View File

@ -0,0 +1,27 @@
using System;
namespace MBS.Framework.Scripting.Strings.StringComponents
{
public class LiteralStringComponent : StringComponent
{
public string Value { get; set; } = null;
public override string ToString(ScriptEnvironment environment)
{
return Value;
}
public override string ToString()
{
return String.Format("\"{0}\"", Value);
}
public LiteralStringComponent(string value)
{
Value = value;
}
public override object Clone()
{
return new LiteralStringComponent(Value?.Clone() as string);
}
}
}