public DataBindingConnection(BaseViewModel viewModel, DataBindInfo dataBindInfo) { this.dataBindInfo = dataBindInfo; this.viewModel = viewModel; _getProperty = ReflectionTool.GetVmPropertyByName(viewModel.GetType(), dataBindInfo.propertyName); if (_getProperty == null) { Debug.LogErrorFormat("get property null {0}:{1}", viewModel.GetType(), dataBindInfo.propertyName); } ReflectionMethodItem item = ReflectionTool.GetComponentMethod(dataBindInfo.component.GetType(), dataBindInfo.invokeFunctionName, _getProperty.PropertyType); if (item == null) { Debug.LogErrorFormat("get invokeMethod null {0}", dataBindInfo.invokeFunctionName); } _invokeMethod = item.methodInfo; foreach (var bindingParameter in dataBindInfo.parameters) { _lstParameter.Add(new BindingParameterInfo(bindingParameter, viewModel)); } ps = new object[dataBindInfo.parameters.Length + 2]; ps[0] = dataBindInfo.component; }
ReflectionMethodItem GetMethod(SerializedProperty property) { DataBindInfo bindingInfo = property.GetSerializedValue <DataBindInfo>(); if (bindingInfo == null) { return(null); } Type tO = property.serializedObject.targetObject.GetType(); FieldInfo viewModelProperty = tO.GetField("ViewModel", BindingFlags.NonPublic | BindingFlags.Instance); Type vmType = viewModelProperty.FieldType; PropertyInfo propertyInfo = vmType.GetProperty(bindingInfo.propertyName); if (propertyInfo == null) { return(null); } ReflectionMethodItem item = ReflectionTool.GetComponentMethod(bindingInfo.component.GetType(), bindingInfo.invokeFunctionName, propertyInfo.PropertyType); return(item); }