static void OnConsoleConfigCommand(string arguments, object userData) { EngineConfig.Parameter parameter = (EngineConfig.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 = SimpleTypes.ParseValue(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 = SimpleTypes.ParseValue(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)); } }
public static void RegisterConfigParameter(EngineConfig.Parameter parameter) { string strType = ""; if (parameter.Field != null) { strType = parameter.Field.FieldType.Name; } else if (parameter.Property != null) { strType = parameter.Property.PropertyType.Name; } string description = string.Format("\"{0}\", Default: \"{1}\"", strType, parameter.DefaultValue); AddCommand(parameter.Name, OnConsoleConfigCommand, parameter, description); }