public static NamedParam[] CreateParams(params object[] paramz) { var paramsz = new List <NamedParam>(); int argNum = 1; for (int i = 0; i < paramz.Length;) { object o = paramz[i++]; if (o is NamedParam) { paramsz.Add((NamedParam)o); continue; } if (o is string) { var k = (string)o; var t = paramz[i++] as Type; string comment = "" + paramz[i++]; var namedParam = new NamedParam(k, t); namedParam.Comment = comment; paramsz.Add(namedParam); } } return(paramsz.ToArray()); }
static private bool KeyMatches(string token, NamedParam param) { var k1 = ToKey(token); var k2 = ToKey(param.Key); return(k1 == k2); }
private static bool TryGetKey(NamedParam param, int argStart, string[] args, out object o, out int used, out int len) { string key = ToKey(param.Key); used = 0; for (int i = argStart; i < args.Length; i++) { used = 1; string s = args[i]; if (ToKey(s) != key) { continue; } if (param.Type == typeof(bool)) { o = true; len = 1; return(true); } if (i + 1 < args.Length) { o = args[i + 1]; len = 2; return(true); } len = MISSING; o = null; return(true); } len = 0; o = null; return(false); }
public static NamedParam Rest(string name, Type type, string description) { var namedParam = new NamedParam(name, type); namedParam.Comment = description; namedParam.IsOptional = true; return(namedParam); }
public ACogbotEvent(object sender, SimEventType type, string name, IEnumerable paramz) { Sender = sender; SetVerb(name); EventType1 = type; Parameters = NamedParam.ObjectsToParams(paramz); CheckStructure(); }
/* * public ACogbotEvent(SimEventStatus status, string eventName, SimEventType type, SimEventClass clazz, IEnumerable<NamedParam> args) * { * SetVerb(eventName); * Parameters = NamedParam.ToArray(args); * EventType = type; * EventStatus = status; * EventClass = clazz; * CheckStructure(); * } */ public ACogbotEvent(object sender, SimEventType type, string name, params NamedParam[] paramz) { Sender = sender; SetVerb(name); EventType1 = type; Parameters = NamedParam.ToArray(paramz); CheckStructure(); }
/// <summary> /// Used for constructing Cyc-like functions /// </summary> /// <param name="param"></param> /// <param name="o"></param> public NamedParam(NamedParam param, object o) : this() { memberTarget = param.memberTarget; _Type = param._Type; _value = o; _key = param._key; Choices = param.Choices; info = param.info; }
//internal SimObjectEvent CombinesWith(SimObjectEvent SE) //{ // if (this.Verb == SE.Verb) // { // if (this.EventStatus == SE.EventStatus) // { // return new SimObjectEvent(Verb, this.EventType, this.EventStatus, this.Parameters, SE.Parameters); // } // if (this.EventStatus == SimEventStatus.Start && SE.EventStatus == SimEventStatus.Stop) // { // return new SimObjectEvent(Verb, this.EventType, SimEventStatus.Once, this.Parameters, SE.Parameters); // } // if (this.EventStatus == SimEventStatus.Once && SE.EventStatus == SimEventStatus.Stop) // { // return new SimObjectEvent(Verb, this.EventType, SimEventStatus.Once, this.Parameters, SE.Parameters); // } // if (this.EventStatus == SimEventStatus.Start && SE.EventStatus == SimEventStatus.Once) // { // return new SimObjectEvent(Verb, this.EventType, SimEventStatus.Once, this.Parameters, SE.Parameters); // } // } // return null; //} public bool SameAs(CogbotEvent SE) { if (Verb != SE.Verb) { return(false); } if (EventType1 != SE.EventType1) { return(false); } if (Parameters == null) { return(SE.Parameters == null); } if (SE.Parameters == null) { return(Parameters == null); } if (Parameters.Length != SE.Parameters.Length) { return(false); } NamedParam[] other = SE.Parameters; for (int i = 0; i < other.Length; i++) { NamedParam otheri = other[i]; if (otheri.Value == null) { if (Parameters[i].Value != null) { return(false); } continue; } if (NonComparable(otheri.GetType())) { continue; } if (!Equals(Parameters[i], otheri)) { return(false); } } return(true); }
private int ValueLen(string key, Type t) { NamedParam kt = GetParm(key); t = t ?? kt.Type; if (t == null) { return(0); } if (t == typeof(bool)) { return(kt.IsOptional ? 0 : 1); } if (kt.IsRest || (t != null && t.IsArray)) { return(-1); } return(1); }
public bool TryGetValueOfType(string key, Type t, out object value) { EnsurePreParsed(); object obj; if (ParamMap.TryGetValue(ToMapKey(key), out obj)) { value = ChangeType(obj, t); return(true); } int len; int at; int keyLen; if (TryGetValueInt(key, t, out value, out at, out len, out keyLen)) { return(true); } if (KeysRequired) { return(false); } NamedParam parm = GetParm(key); if (parm.IsOptional) { return(false); } if (this.StartArg >= tokens.Length) { return(false); } len = LenCheck(StartArg, len); value = ChangeType(GetRange(StartArg, len), t); StartArg += len; return(true); }
private object ParseArg(NamedParam param, Type parseFor, string[] text, int start, out int argsUsed) { argsUsed = 1; return(text[start]); }