/// <summary> /// Retorna el metodo en cuestion /// </summary> /// <param name="methodCodeName"></param> /// <returns></returns> public MethodBuilder GetMethodBuilder(string methodCodeName) { if (!DefinedMethod.ContainsKey(methodCodeName)) { throw new ArgumentException("El metodo no se annadido a la clase codigo"); } return(DefinedMethod[methodCodeName]); }
/// <summary> /// Adiciona un metodo builder a la clase codigo /// </summary> /// <param name="methodCodeName"></param> /// <param name="mBuilder"></param> public void AddMethodBuilder(string methodCodeName, MethodBuilder mBuilder) { if (DefinedMethod.ContainsKey(methodCodeName)) { throw new ArgumentException("Un metodo con ese nombre ya fue declarado en el codigo"); } DefinedMethod.Add(methodCodeName, mBuilder); }
public void EvaluateDefinedMethod() { Context context = new Context(); IList <ICommand> commandlist = new List <ICommand>(); commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1))); commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2))); commandlist.Add(new ExpressionCommand(new VariableExpression("b"))); CompositeCommand commands = new CompositeCommand(commandlist); DefinedMethod method = new DefinedMethod(null, commands); context.SetValue("foo", method); VariableExpression expr = new VariableExpression("foo"); Assert.AreEqual(2, expr.Evaluate(context)); }
public void ExecuteCallExpression() { Context context = new Context(); IList <ICommand> commandlist = new List <ICommand>(); commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1))); commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2))); commandlist.Add(new ExpressionCommand(new VariableExpression("b"))); CompositeCommand commands = new CompositeCommand(commandlist); DefinedMethod method = new DefinedMethod(null, commands); CallExpression callexpr = new CallExpression(new ConstantExpression(method), null); object result = callexpr.Evaluate(context); Assert.AreEqual(2, result); }
public void ExecuteDefinedMethod() { Context context = new Context(); IList <ICommand> commandlist = new List <ICommand>(); commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1))); commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2))); commandlist.Add(new ExpressionCommand(new VariableExpression("b"))); CompositeCommand commands = new CompositeCommand(commandlist); DefinedMethod method = new DefinedMethod(null, commands); object result = method.Call(context, null); Assert.IsNotNull(result); Assert.AreEqual(2, result); Assert.IsNull(context.GetValue("a")); Assert.IsNull(context.GetValue("b")); }
/// <summary> /// Asocia una funcion con el wrapper que ella crea. /// </summary> /// <param name="functionCodeName"></param> /// <param name="typeWrapperCodeName"></param> public void AsociatteMethodToWrapper(string functionCodeName, string typeWrapperCodeName) { if (!DefinedMethod.ContainsKey(functionCodeName)) { throw new ArgumentException("La funcion debe ser annadida antes"); } if (!DefinedType.ContainsKey(typeWrapperCodeName)) { throw new ArgumentException("El tipo tiene que ser annadido antes"); } if (FuntionWrapper.ContainsKey(functionCodeName)) { throw new ArgumentException("Ya se ha asociado esa funcion a ese tipo"); } var typeBuilder = (TypeBuilder)DefinedType[typeWrapperCodeName]; var typeCodeInfo = new TypeCodeInfo { TypeCodeName = typeWrapperCodeName, Type = typeBuilder }; FuntionWrapper.Add(functionCodeName, typeCodeInfo); }