// Unbox <token>
        // Revert a boxed value type instance from the object form to its value type form. <token> specifies the value type being converted and must be a valid TypeDef or TypeRef token.
        // This instruction takes an object reference from the stack and puts a managed pointer to the value type instance on the stack.

        /// <summary>
        /// Writes the Unbox and ldobj instruction (Unbox.any = Unbox + ldobj)
        /// </summary>
        /// <param name="indent">Indentation to use.</param>
        /// <param name="type">Value type to revert.</param>
        public override void UnboxAny(int indent, TypeExpression type)
        {
            if (type is UnionType)
            {
                this.UnboxAny(indent, type as UnionType);
            }
            else if (!(type is TypeVariable))
            {
                this.WriteLNUnaryCommand(indent, "unbox.any", type.ILType());
            }
            else if (((TypeVariable)type).Substitution != null)
            {
                this.WriteLNUnaryCommand(indent, "unbox.any", type.ILType());
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Obtains the type if the current argument by means of introspection
 /// </summary>
 /// <param name="index">index of the current argument</param>
 /// <param name="argType">type of the current argument</param>
 private void IntropectiveInvocationLoadArgument(int index, TypeExpression argType)
 {
     this.codeGenerator.dup(this.indent);
     this.codeGenerator.ldci4(this.indent, index);
     this.codeGenerator.ldtoken(this.indent, TypeMapping.Instance.GetBCLName(argType.ILType(), true));
     this.codeGenerator.Call(this.indent, "class", "[mscorlib]System.Type", "[mscorlib]System.Type", "GetTypeFromHandle", new string[] { "valuetype [mscorlib]System.RuntimeTypeHandle" });
     this.codeGenerator.stelemRef(this.indent);
 }
        private static String[] TypeExpressionRepresentation(TypeExpression typeExpression, bool original = false)
        {
            if (typeExpression.ILType().Equals("class [mscorlib]System.Object"))
            {
                return new string[] { "object" }
            }
            ;
            if (typeExpression.ILType().Contains("class"))
            {
                return new string[] { typeExpression.ILType().Replace("class ", "").Replace(".", "_") }
            }
            ;

            UnionType ut = null;

            if (typeExpression is UnionType)
            {
                ut = (UnionType)typeExpression;
            }
            else if (typeExpression is TypeVariable && ((TypeVariable)typeExpression).Substitution is UnionType)
            {
                ut = (UnionType)((TypeVariable)typeExpression).Substitution;
            }

            if (ut != null)
            {
                List <String> result = new List <string>();
                foreach (var expression in ut.TypeSet)
                {
                    foreach (var typeRepresentation in TypeExpressionRepresentation(expression, original))
                    {
                        if (!result.Contains(typeRepresentation))
                        {
                            result.Add(typeRepresentation);
                        }
                    }
                }
                return(result.ToArray());
            }
            if (original && typeExpression is TypeVariable && ((TypeVariable)typeExpression).Substitution == null)
            {
                return new string[] { TypeVariable.NewTypeVariable.ILType() }
            }
            ;
            return(new string[] { typeExpression.ILType() });
        }
 /// <summary>
 /// Writes the current type information
 /// </summary>
 /// <param name="type">WriteType expression with the type information.</param>
 internal void WriteType(TypeExpression type)
 {
     this.Write(type.ILType());
 }
 /// <summary>
 /// Writes the field inicialization.
 /// </summary>
 /// <param name="type">WriteType Expression of the field inicialization.</param>
 internal void WriteFieldInitialization(TypeExpression type)
 {
     this.Write(" = {0}(", type.ILType());
 }
        // Unbox <token>
        // Revert a boxed value type instance from the object form to its value type form. <token> specifies the value type being converted and must be a valid TypeDef or TypeRef token.
        // This instruction takes an object reference from the stack and puts a managed pointer to the value type instance on the stack.

        /// <summary>
        /// Writes the Unbox and ldobj instruction
        /// </summary>
        /// <param name="indent">Indentation to use.</param>
        /// <param name="type">Value type to revert.</param>
        public override void UnboxAny(int indent, TypeExpression type)
        {
            this.ilStamentsCodeGeneration.WriteIndentation(indent);
            this.ilStamentsCodeGeneration.WriteLine("Unbox\t{0}", type.ILType());
            this.ilStamentsCodeGeneration.WriteLine("ldobj\t{0}", type.ILType());
        }
Exemplo n.º 7
0
        // Unbox <token>
        // Revert a boxed value type instance from the object form to its value type form. <token> specifies the value type being converted and must be a valid TypeDef or TypeRef token.
        // This instruction takes an object reference from the stack and puts a managed pointer to the value type instance on the stack.

        /// <summary>
        /// Writes the Unbox and ldobj instruction (Unbox.any = Unbox + ldobj)
        /// </summary>
        /// <param name="indent">Indentation to use.</param>
        /// <param name="type">Value type to revert.</param>
        public override void UnboxAny(int indent, TypeExpression type)
        {
            this.WriteLNUnaryCommand(indent, "unbox.any", type.ILType());
        }