public VariableTBase Invoke(string name, VariableTBase[] args) { List <Invokable> invs; lock (functions) { if (!functions.ContainsKey(name)) { access.WriteText(ConsoleErrorMessages.FunctionNotFound); throw new Exceptions.ShellFunctionNotFound(); } else { invs = functions[name]; } } foreach (Invokable ivb in invs) { ArgResult rs = CheckPopulateArgs(args, ivb); if (!rs.IsCorrect) { continue; } MethodInfo minf = ivb.CallStd.generic ? rs.genCr : ivb.MInfo; object o = minf.Invoke(null, rs.arguments); VariableTBase vb = (VariableTBase)o; return(vb); } throw new Exceptions.ShellFunctionNotFound(); return(null); }
public static VariableTBase ParseCreateVariable(string type, string parse, TextDisplay WriteTextOnConsoleBuffer) { Type t = Type.GetType(type); if (t == null) { WriteTextOnConsoleBuffer("Type " + type + " not found."); return(null); } System.Reflection.MethodInfo minf; try { minf = t.GetMethod("Parse", new Type[] { typeof(string) }); } catch (System.Reflection.AmbiguousMatchException e) { WriteTextOnConsoleBuffer("Multiple matches for parsing method; not supported."); return(null); } if (minf == null) { WriteTextOnConsoleBuffer("No parsing method found."); return(null); } object o; try { o = minf.Invoke(null, new object[] { parse }); } catch { WriteTextOnConsoleBuffer("Badly formatted text"); return(null); } if (o == null) { WriteTextOnConsoleBuffer("Badly formatted text."); return(null); } MethodInfo eim = typeof(InvokerSet).GetMethod("MakeVariableT", BindingFlags.NonPublic | BindingFlags.Static); MethodInfo im = eim.MakeGenericMethod(t); VariableTBase vb = (VariableTBase)im.Invoke(null, new object[] { o }); return(vb); }