static public object GetValueFromConstant(VariableType type, ConstantType constant) { object result = null; if (constant.HasBoolean()) { bool boolValue = (bool)constant.GetBoolean().Value; switch(type) { case VariableType.BOOLEAN: result = boolValue; break; case VariableType.INT: result = (int)(boolValue ? 1 : 0); break; case VariableType.FLOAT: result = (float)(boolValue ? 1 : 0); break; case VariableType.STRING: result = (boolValue ? "true" : "false"); break; } } else if (constant.HasInteger()) { int intValue = (int)constant.GetInteger().Value; switch(type) { case VariableType.BOOLEAN: result = (intValue == 1) ? true : false; break; case VariableType.INT: result = intValue; break; case VariableType.FLOAT: result = intValue; break; case VariableType.STRING: result = intValue.ToString(); break; } } else if (constant.HasFloat2()) { float floatValue = (float)constant.GetFloat2().Value; switch(type) { case VariableType.BOOLEAN: result = (floatValue == 1) ? true : false; break; case VariableType.INT: result = (int)floatValue; break; case VariableType.FLOAT: result = floatValue; break; case VariableType.STRING: result = floatValue.ToString(); break; } } else if (constant.HasString2()) { string stringValue = constant.GetString2().Value; switch(type) { case VariableType.BOOLEAN: result = (stringValue == "true") ? true : false; break; case VariableType.STRING: result = stringValue; break; case VariableType.INT: result = stringValue; break; case VariableType.FLOAT: result = Convert.ToSingle(stringValue); break; } } return result; }
static public object GetValueFromConstant(ConstantType constant) { object result = null; if (constant.HasBoolean()) { result = (bool)constant.GetBoolean().Value; } else if (constant.HasInteger()) { result = (int)constant.GetInteger().Value; } else if (constant.HasFloat2()) { result = (float)constant.GetFloat2().Value; } else if (constant.HasString2()) { result = (string)constant.GetString2().Value; } return result; }