public override void RenameVariable(string oldName, string newName) { if (ModelDataInputs.Concat(ModelDataOutputs).FirstOrDefault(d => d.Name == newName) == null) { return; } var separators = new HashSet <char>(new char[] { '[', ']', '{', '}', ';', '.', ',', '(', ')', '"', '\'', '+', '-', '*', '/', '%', ' ', '\t', '\n' }); FunctionBody = Replace(FunctionBody); Code = Signature + "\n{\n" + FunctionBody + "\n}"; Compiled = false; string Replace(string text) { int index = -1; do { index = text.IndexOf(oldName, index + 1); if (index == -1) { continue; } if (index > 0 && !separators.Contains(text[index - 1])) { continue; } if (index < text.Length - 1 - oldName.Length && !separators.Contains(text[index + oldName.Length])) { continue; } text = text.Substring(0, index) + newName + text.Substring(index + oldName.Length); } while (index != -1); return(text); } }
public List <Data> GetAllData() => ModelDataInputs.Concat(ModelDataOutputs).ToList();
public override bool Execute() { int Ninputs = ModelDataInputs.Count; int Nout = Math.Min(methodInfo.GetParameters().Where(p => p.IsOut).Count(), ModelDataOutputs.Count); object[] parameters = ModelDataInputs.Concat(ModelDataOutputs.Take(Nout)).Select(i => i.Value).ToArray(); //for (int i = 0; i < Nout; i++) // inputs.Add(ModelDataOutputs[i].Value); //inputs.Add(Activator.CreateInstance(Type.GetType(param.ParameterType.FullName.TrimEnd('&')))); try { //object[] parameters = inputs.ToArray(); object outputs = methodInfo.Invoke(classInstance, parameters); Type outputType = outputs?.GetType() ?? typeof(void); for (int i = 0; i < Nout; i++) { ModelDataOutputs[i].Value = parameters[Ninputs + i]; } int idx = 0; if (outputs is object[] arr) { int N = Math.Min(arr.Length, ModelDataOutputs.Count); for (int i = 0; i < N; i++) { // Assign ModelDataOutputs[Nout + i].Value = arr[i]; } idx = N; } else if (outputType.IsSuported()) { ModelDataOutputs.First().Value = outputs; idx = 1; } else { PropertyInfo[] properties = outputType.GetProperties().Where(p => p.GetMethod.IsPublic && p.PropertyType.IsSuported()).ToArray(); FieldInfo[] fields = outputType.GetFields().Where(f => f.IsPublic && f.FieldType.IsSuported()).ToArray(); int N = Math.Min(properties.Length, ModelDataOutputs.Count); int M = Math.Min(fields.Length, ModelDataOutputs.Count - N); for (int i = 0; i < N; i++) { // Assign ModelDataOutputs[Nout + i].Value = properties[i].GetValue(outputs); } for (int i = 0; i < M; i++) { // Assign ModelDataOutputs[Nout + N + i].Value = fields[i].GetValue(outputs); } idx = N + M; } } catch (Exception e) { Console.WriteLine(e.Message); return(false); } return(true); }