// Use this for initialization public static void Init(GameConsolePanelSettingConfig config, Action OnTriggerBoot) { Type[] types = ReflectionTool.GetChildTypes(typeof(BootFunctionBase)); Debug.Log("types.cout:" + types.Length); foreach (var item in types) { object obj = ReflectionTool.CreateDefultInstance(item); if (obj != null) { BootFunctionBase function = (BootFunctionBase)obj; bootFunctions.Add(function); } } foreach (var item in bootFunctions) { try { item.OnInit(config, OnTriggerBoot); } catch (Exception e) { Debug.LogError(e); } } }
private static object JsonObjectToList(object obj, Type itemType) { IList <object> listData = obj as IList <object>; Type listType = list_Type.MakeGenericType(itemType); object list = ReflectionTool.CreateDefultInstance(listType); if (listData == null || listData.Count == 0) { return(list); } MethodInfo addMethod = listType.GetMethod("Add"); for (int i = 0; i < listData.Count; i++) { object obj0 = listData[i]; obj0 = ChangeJsonDataToObjectByType(itemType, obj0); if (obj0 == null) { continue; } addMethod.Invoke(list, new object[] { obj0 }); } return(list); }
public object GetDefaultValue() { Type type = GetParamValueType(); if (type == null) { return(null); } if (string.IsNullOrEmpty(defaultValueStr)) { return(ReflectionTool.CreateDefultInstance(type)); } return(SimpleJsonUtils.FromJson(type, defaultValueStr)); }
private static object JsonObjectToClassOrStruct(object jsonObj, Type type) { IDictionary <object, object> dic = (IDictionary <object, object>)jsonObj; object instance = ReflectionTool.CreateDefultInstance(type); if (dic == null || instance == null) { return(null); } foreach (var item in dic) { string key = item.Key.ToString(); object value = item.Value; FieldInfo f = type.GetField(key, flags); if (f != null) { value = ChangeJsonDataToObjectByType(f.FieldType, value); f.SetValue(instance, value); } else { PropertyInfo p = type.GetProperty(key, flags); if (CheckPropertyInfo(p)) { try { value = ChangeJsonDataToObjectByType(p.PropertyType, value); p.SetValue(instance, value, null); } catch (Exception e) { Debug.LogError("property :" + p.Name + "\n" + e); continue; } } } } return(instance); }
private string GetDefaultValueString(Type classType, Type parameterType, ParamsDescriptionAttribute paramsDescription) { object value = null; if (paramsDescription != null && !string.IsNullOrEmpty(paramsDescription.getDefaultValueMethodName)) { MethodInfo info = classType.GetMethod(paramsDescription.getDefaultValueMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (info != null) { Type returnType = info.ReturnType; if (returnType != parameterType) { Debug.LogError("GetDefaultValueString Method:" + classType.FullName + "." + paramsDescription.getDefaultValueMethodName + " ReturnType(" + returnType.FullName + ") is different from parameterType(" + parameterType + ")"); } else { try { value = info.Invoke(null, new object[0]); } catch (Exception e) { Debug.LogError(e); } } } } if (value == null) { Debug.Log("CreateDefultInstance Type:" + parameterType); value = ReflectionTool.CreateDefultInstance(parameterType); } return(SimpleJsonUtils.ToJson(value)); }