static void InvokeMethod(QueryArgMethodInfo queryArgMethod, KeyValuePair <string, string> kv) { var parameter = queryArgMethod.method.GetParameters().FirstOrDefault(); if (parameter != null) { if (parameter.ParameterType.Equals(typeof(int))) { if (int.TryParse(kv.Value, out int intValue)) { queryArgMethod.method.Invoke(queryArgMethod.component, new object[] { intValue }); } return; } if (parameter.ParameterType.Equals(typeof(bool))) { if (bool.TryParse(kv.Value, out bool boolValue)) { queryArgMethod.method.Invoke(queryArgMethod.component, new object[] { boolValue }); } return; } if (parameter.ParameterType.Equals(typeof(double))) { if (double.TryParse(kv.Value, out double doubleValue)) { queryArgMethod.method.Invoke(queryArgMethod.component, new object[] { doubleValue }); } return; } if (parameter.ParameterType.Equals(typeof(float))) { if (float.TryParse(kv.Value, out float floatValue)) { queryArgMethod.method.Invoke(queryArgMethod.component, new object[] { floatValue }); } return; } // Default to string type queryArgMethod.method.Invoke(queryArgMethod.component, new object[] { kv.Value }); } else { // If same values, even empty, Invoke parameterless method if (queryArgMethod.value.Equals(kv.Value)) { queryArgMethod.method.Invoke(queryArgMethod.component, null); } } }
static void Register(Component component, string key, MethodInfo setter, MethodInfo getter = null, string value = "") { var queryArgSetter = new QueryArgMethodInfo() { component = component, key = key, value = value, method = setter, }; m_QueryArgSetterList.Add(queryArgSetter); if (getter != null) { var queryArgGetter = new QueryArgMethodInfo() { component = component, key = key, value = value, method = getter, }; m_QueryArgGetterList.Add(queryArgGetter); } }
public static void RegisterMethod(QueryArgMethodInfo queryArgMethodInfo) { m_QueryArgSetterList.Add(queryArgMethodInfo); }