This repository has been archived by the owner on May 19, 2019. It is now read-only.
/
CommandBase.cs
57 lines (50 loc) · 1.53 KB
/
CommandBase.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
49
50
51
52
53
54
55
56
57
using System;
using System.IO;
using System.Text;
using LPS.ToolScript.Parser;
using LPS.ToolScript;
namespace LPS.Util
{
public abstract class CommandBase : ICommand, IFunction
{
private string name;
protected CommandBase(string Name)
{
this.name = Name;
}
public string Name { get { return this.name; } }
public virtual string Help
{
get { return "nedokumentováno";}
}
protected T Get<T>(object[] parameters, int index)
{
if(parameters == null || index >= parameters.Length)
return default(T);
object val = parameters[index];
if(val == null || val is T)
return (T)val;
return (T)Convert.ChangeType(val, typeof(T));
}
public abstract object Execute(IExecutionContext context, TextWriter Out, TextWriter Info, TextWriter Err, object[] Params);
public EventHandler GetEventHandler (IExecutionContext CustomContext)
{
throw new System.NotImplementedException ();
}
public override string ToString ()
{
return String.Format("function {0}(...);", Name);
}
public virtual object Execute (NamedArgumentList argumentValues)
{
IExecutionContext context = UtilMainWindow.Instance.ParserContext;
TextWriter Out = (TextWriter)context.GetVariable("__STD_OUT");
TextWriter Info = (TextWriter)context.GetVariable("__STD_INFO");
TextWriter Err = (TextWriter)context.GetVariable("__STD_ERR");
object[] args = new object[argumentValues.Count];
for(int i=0; i<argumentValues.Count; i++)
args[i] = argumentValues[i].Value;
return Execute(context, Out, Info, Err, args);
}
}
}