private void BuildMethodTable() { var type = this.GetType(); var srcMethods = type.GetMethods(BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance); var methods = new List <ContractMethod>(); var ignore = new HashSet <string>(new string[] { "ToString", "GetType", "Equals", "GetHashCode", "CallMethod", "SetTransaction" }); foreach (var srcMethod in srcMethods) { var parameters = new List <ContractParameter>(); var srcParams = srcMethod.GetParameters(); var methodName = srcMethod.Name; if (methodName.StartsWith("get_")) { methodName = methodName.Substring(4); } if (ignore.Contains(methodName)) { continue; } var isVoid = srcMethod.ReturnType == typeof(void); var returnType = isVoid ? VMType.None : VMObject.GetVMType(srcMethod.ReturnType); bool isValid = isVoid || returnType != VMType.None; if (!isValid) { continue; } foreach (var srcParam in srcParams) { var paramType = srcParam.ParameterType; var vmtype = VMObject.GetVMType(paramType); if (vmtype != VMType.None) { parameters.Add(new ContractParameter(srcParam.Name, vmtype)); } else { isValid = false; break; } } if (isValid) { _methodTable[methodName] = srcMethod; var method = new ContractMethod(methodName, returnType, parameters.ToArray()); methods.Add(method); } } this.ABI = new ContractInterface(methods); }
private void BuildMethodTable() { var type = this.GetType(); var srcMethods = type.GetMethods(BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.DeclaredOnly); var methods = new List <ContractMethod>(); foreach (var srcMethod in srcMethods) { var parameters = new List <ContractParameter>(); var srcParams = srcMethod.GetParameters(); var methodName = srcMethod.Name; if (methodName.StartsWith("get_")) { methodName = methodName.Substring(4); } if (methodName == "Kind") { continue; } var isVoid = srcMethod.ReturnType == typeof(void); var returnType = isVoid ? VMType.None : VMObject.GetVMType(srcMethod.ReturnType); bool isValid = isVoid || returnType != VMType.None; if (!isValid) { continue; } foreach (var srcParam in srcParams) { var paramType = srcParam.ParameterType; var vmtype = VMObject.GetVMType(paramType); if (vmtype != VMType.None) { parameters.Add(new ContractParameter(srcParam.Name, vmtype)); } else { isValid = false; break; } } if (isValid) { _methodTable[methodName] = srcMethod; var method = new ContractMethod(methodName, returnType, -1, parameters.ToArray()); methods.Add(method); } } this.ABI = new ContractInterface(methods, Enumerable.Empty <ContractEvent>()); }
private static ExecutionState Constructor_Object <IN, OUT>(RuntimeVM vm, Func <IN, OUT> loader) { var type = VMObject.GetVMType(typeof(IN)); var input = vm.Stack.Pop().AsType(type); try { OUT obj = loader((IN)input); var temp = new VMObject(); temp.SetValue(obj); vm.Stack.Push(temp); } catch { return(ExecutionState.Fault); } return(ExecutionState.Running); }
private static ExecutionState Constructor_Object <IN, OUT>(VirtualMachine vm, Func <IN, OUT> loader) { var rawInput = vm.Stack.Pop(); var inputType = VMObject.GetVMType(typeof(IN)); var convertedInput = rawInput.AsType(inputType); try { OUT obj = loader((IN)convertedInput); var temp = new VMObject(); temp.SetValue(obj); vm.Stack.Push(temp); } catch (Exception e) { throw new VMException(vm, e.Message); } return(ExecutionState.Running); }