initial scaffolding for programmatic scripting support (e.g. via XML)
This commit is contained in:
parent
78a3b73cf6
commit
c275c25d0a
@ -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>
|
||||
|
||||
8
MBS.Framework/Scripting/ScriptEnvironment.cs
Normal file
8
MBS.Framework/Scripting/ScriptEnvironment.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using System;
|
||||
namespace MBS.Framework.Scripting
|
||||
{
|
||||
public class ScriptEnvironment
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
54
MBS.Framework/Scripting/Strings/ScriptableString.cs
Normal file
54
MBS.Framework/Scripting/Strings/ScriptableString.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
MBS.Framework/Scripting/Strings/StringComponent.cs
Normal file
16
MBS.Framework/Scripting/Strings/StringComponent.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using MBS.Framework.Logic.Conditional;
|
||||
|
||||
namespace MBS.Framework.Scripting.Strings.StringComponents
|
||||
{
|
||||
public class ConditionalStringComponent
|
||||
{
|
||||
public IConditionalStatement Condition { get; }
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user