public void TestJsonValues() { var enumType = new CorePackage.Entity.Type.EnumType(); enumType.Name = "MoreOrLess"; enumType.SetValue("NONE", new CorePackage.Entity.Variable(CorePackage.Entity.Type.Scalar.Integer, 0)); enumType.SetValue("MORE", new CorePackage.Entity.Variable(CorePackage.Entity.Type.Scalar.Integer, 1)); enumType.SetValue("LESS", new CorePackage.Entity.Variable(CorePackage.Entity.Type.Scalar.Integer, 2)); Assert.IsTrue(enumType.CreateFromJSON("MoreOrLess.NONE") == 0); Assert.IsTrue(enumType.CreateFromJSON("2") == 2); }
public void TestTypeCompatibility() { var enumType = new CorePackage.Entity.Type.EnumType(); enumType.SetValue("NONE", new CorePackage.Entity.Variable(CorePackage.Entity.Type.Scalar.Integer, 0)); enumType.SetValue("MORE", new CorePackage.Entity.Variable(CorePackage.Entity.Type.Scalar.Integer, 1)); enumType.SetValue("LESS", new CorePackage.Entity.Variable(CorePackage.Entity.Type.Scalar.Integer, 2)); short shortVal = 0; ushort ushortVal = 0; int intVal = 1; uint uintVal = 1; long longVal = 2; long ulongVal = 2; COMPARISON enumVal = COMPARISON.MORE; Assert.IsTrue(enumType.IsValueOfType(shortVal)); Assert.IsTrue(enumType.IsValueOfType(ushortVal)); Assert.IsTrue(enumType.IsValueOfType(intVal)); Assert.IsTrue(enumType.IsValueOfType(uintVal)); Assert.IsTrue(enumType.IsValueOfType(longVal)); Assert.IsTrue(enumType.IsValueOfType(ulongVal)); Assert.IsTrue(enumType.IsValueOfType(enumVal)); }
/// <summary> /// Set an enumeration value /// </summary> /// <param name="enumID">Identifier of specific enumeration</param> /// <param name="name">Name of the enum value to set</param> /// <param name="value">Value to set in the enum</param> public void SetEnumerationValue(UInt32 enumID, string name, dynamic value) { CorePackage.Entity.Type.EnumType to_find = entity_factory.FindDefinitionOfType <CorePackage.Entity.Type.EnumType>(enumID); CorePackage.Entity.Variable var = new CorePackage.Entity.Variable(to_find.Stored, value); to_find.SetValue(name, var); }