Example #1
0
        /* Performs unboxing of value
         * (corresponds to CILPE.CFG.UnboxValue class)
         */
        public void Perform_UnboxValue(Type type, out Exception exc)
        {
            exc = null;

            Value val = Pop();

            if (val is NullValue)
            {
                exc = new NullReferenceException();
            }
            else if (!(val is ObjectReferenceValue))
            {
                throw new InvalidOperandException();
            }

            if (exc == null)
            {
                object obj = (val as ObjectReferenceValue).Obj;

                Type objType = obj.GetType();
                if (objType.IsEnum)
                {
                    objType = StructValue.getEnumType(objType);
                }

                if (objType != type)
                {
                    exc = new InvalidCastException();
                }
                else
                {
                    push(new PointerToUnboxedValue(obj));
                }
            }
        }