public static int?convertToOptionalInt(Pattern <Decoration> pattern) { if (pattern.@is(Pattern <Decoration> .EnumType.DECORATEDVALUE)) { Interpreter.vmAssert(pattern.decoration != null, false, "Must have a decoration"); Interpreter.vmAssert(pattern.decoration.type == Decoration.EnumType.VALUE, false, "Must be a value"); Interpreter.vmAssert(pattern.decoration.value is long, false, "Must be long"); try { return(Convert.ToInt32(pattern.decoration.value)); } catch (OverflowException e) { throw new Exception("Value overflow!"); // TODO< rewrite to except which is thrown by vmAssert() > } } else if (pattern.@is(Pattern <Decoration> .EnumType.SYMBOL)) // special symbol for "null" // 0 is reserved for the "null" word { Interpreter.vmAssert(pattern.uniqueId == 0, false, "Special uniqueId equal to 0 expected to encode \"null\""); return(null); } else { Interpreter.vmAssert(false, false, "expected value or special symbol"); throw new Exception(); // make compiler happy } }
public static int convertToInt(Pattern <Decoration> pattern) { Interpreter.vmAssert(pattern.@is(Pattern <Decoration> .EnumType.DECORATEDVALUE), false, "Must have a decoration"); Interpreter.vmAssert(pattern.decoration != null, false, "Must have a decoration"); Interpreter.vmAssert(pattern.decoration.type == Decoration.EnumType.VALUE, false, "Must be a value"); Interpreter.vmAssert(pattern.decoration.value is long, false, "Must be long"); try { return(Convert.ToInt32(pattern.decoration.value)); } catch (OverflowException e) { throw new Exception("Value overflow!"); // TODO< rewrite to except which is thrown by vmAssert() > } }