static void ConsoleCommand_ShowDebugInformationWindow(string arguments) { bool show = DebugInformationWindow.Instance == null; try { show = (bool)SimpleTypesUtils.GetSimpleTypeValue(typeof(bool), arguments); } catch { } ShowDebugInformationWindow(show); }
protected override bool OnLoad(TextBlock block) { if (!base.OnLoad(block)) { return(false); } if (block.IsAttributeExist("value")) { this.aBX = SimpleTypesUtils.GetSimpleTypeValue(this.aBw, block.GetAttribute("value")); } return(true); }
private void OnConsoleConfigCommand(string arguments, object userData) { Config.Parameter parameter = (Config.Parameter)userData; if (string.IsNullOrEmpty(arguments)) { object value = parameter.GetValue(); Print(string.Format("Value: \"{0}\", Default value: \"{1}\"", value != null ? value : "(null)", parameter.DefaultValue)); return; } try { if (parameter.Field != null) { object value = SimpleTypesUtils.GetSimpleTypeValue(parameter.Field.FieldType, arguments); if (value == null) { throw new Exception("Not simple type"); } parameter.Field.SetValue(null, value); } else if (parameter.Property != null) { object value = SimpleTypesUtils.GetSimpleTypeValue(parameter.Property.PropertyType, arguments); if (value == null) { throw new Exception("Not simple type"); } parameter.Property.SetValue(null, value, null); } } catch (FormatException e) { string s = ""; if (parameter.Field != null) { s = parameter.Field.FieldType.ToString(); } else if (parameter.Property != null) { s = parameter.Property.PropertyType.ToString(); } Print(string.Format("Config : Invalid parameter format \"{0}\" {1}", s, e.Message), new ColorValue(1, 0, 0)); } }
/// <summary> /// 数据转换: 将<paramref name="strValue"/>转化成<paramref name="type"/>,输出<paramref name="outValue"/> /// </summary> /// <param name="type"></param> /// <param name="strValue"></param> /// <param name="errorString"></param> /// <param name="outValue"></param> /// <returns></returns> public static bool ConvertFromString(Type type, string strValue, string errorString, out object outValue) { outValue = null; try { #region Simple Type if (SimpleTypesUtils.IsSimpleType(type)) { if (strValue == "") { if (type == typeof(string)) { outValue = ""; return(true); } if (errorString != null) { Log.Error("Entity System: Serialization error. The invalid value \"{0}\" for type \"{1}\" ({2}).", strValue, type, errorString); } return(false); } outValue = SimpleTypesUtils.GetSimpleTypeValue(type, strValue); return(outValue != null); } #endregion #region Entity if (typeof(Entity).IsAssignableFrom(type)) { if (strValue == "null" || strValue == "") { return(true); } Entity loadingEntityBySerializedUIN = Entities.Instance.GetLoadingEntityBySerializedUIN(uint.Parse(strValue)); bool isEntityExists = (EntitySystemWorld.Instance.IsSingle() || EntitySystemWorld.Instance.IsEditor()) && loadingEntityBySerializedUIN == null; if (isEntityExists) { if (errorString != null) { Log.Error("Entity System: Serialization error. The entity with UIN \"{0}\" is not exists ({1}).", strValue, errorString); } return(false); } outValue = loadingEntityBySerializedUIN; return(true); } #endregion #region EntityType if (typeof(EntityType).IsAssignableFrom(type)) { if (strValue == "null" || strValue == "") { return(true); } EntityType byName = EntityTypes.Instance.GetByName(strValue); if (byName == null) { if (errorString != null) { Log.Error("Entity System: Serialization error. The entity type is not defined \"{0}\" ({1}).", strValue, errorString); } return(false); } outValue = byName; return(true); } #endregion #region typeof(Type) == type if (typeof(Type) == type) { if (strValue == "null" || strValue == "") { return(true); } if (strValue.Contains("Engine.UISystem.E")) { string[] rControl = new string[] { "VideoBox", "Button", "CheckBox", "ComboBox", "Control", "EditBox", "ListBox", "ScrollBar", "TabControl", "TextBox" }; for (int i = 0; i < rControl.Length; i++) { string str = rControl[i]; bool flag17 = strValue == "Engine.UISystem.E" + str; if (flag17) { strValue = "Engine.UISystem." + str; break; } } } Type typeControl = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int j = 0; j < assemblies.Length; j++) { Assembly assembly = assemblies[j]; typeControl = assembly.GetType(strValue); if (typeControl != null) { break; } } if (typeControl == null) { if (errorString != null) { Log.Error("Entity System: Serialization error. The entity type is not found \"{0}\" ({1}).", strValue, errorString); } return(false); } outValue = typeControl; return(true); } #endregion if (errorString != null) { Log.Fatal("Entity System: Serialization for type \"{0}\" are not supported ({1}).", type.ToString(), errorString); } return(false); } catch (FormatException ex) { if (errorString != null) { Log.Error("Entity System: Serialization error: \"{0}\" ({1}).", ex.Message, errorString); } return(false); } }