public Value MakeConstant(AiRuleEngine.VariableType type, object value) { Value newValue = new Value(); ConstantType newConstant = new ConstantType(); switch (type) { case AiRuleEngine.VariableType.BOOLEAN: newConstant.AddBoolean(new Altova.Types.SchemaBoolean((bool)value)); break; case AiRuleEngine.VariableType.INT: newConstant.AddInteger(new Altova.Types.SchemaLong((long)(int)value)); break; case AiRuleEngine.VariableType.FLOAT: newConstant.AddFloat2(new Altova.Types.SchemaDecimal((decimal)(float)value)); break; case AiRuleEngine.VariableType.STRING: newConstant.AddString2(new Altova.Types.SchemaString((string)value)); break; } newValue.AddConstant(newConstant); return newValue; }
static public ConstantType GetConstantFromValue(VariableType type, object value) { if (value == null) { Debug.LogError("Error null value in GetConstantFromValue"); return null; } ConstantType constantType = new ConstantType(); switch (type) { case VariableType.BOOLEAN: constantType.AddBoolean(new SchemaBoolean((bool)value)); break; case VariableType.FLOAT: constantType.AddFloat2(new SchemaDecimal((decimal)(float)value)); break; case VariableType.INT: constantType.AddInteger(new SchemaLong((long)(int)value)); break; case VariableType.STRING: constantType.AddString2(new SchemaString((string)value)); break; } return constantType; }
static public ConstantType GetConstantFromValue(object value) { if (value == null) { Debug.LogError("Error null value in GetConstantFromValue"); return null; } ConstantType constantType = new ConstantType(); if (value.GetType() == typeof(bool)) { constantType.AddBoolean(new SchemaBoolean((bool)value)); } else if (value.GetType() == typeof(float)) { constantType.AddFloat2(new SchemaDecimal((decimal)(float)value)); } else if (value.GetType() == typeof(int)) { long longValue = (long)(int)value; constantType.AddInteger(new SchemaLong(longValue)); } else if (value.GetType() == typeof(string)) { constantType.AddString2(new SchemaString((string)value)); } else { string objectString; if (ObjectToString(value, out objectString)) constantType.AddString2(new SchemaString(objectString)); else constantType.AddString2(new SchemaString(value.GetType().ToString())); } return constantType; }