Ejemplo n.º 1
0
        private static void AddBox(IMember m, IEmitter emitter, JObject properties)
        {
            bool needBox = ConversionBlock.IsBoxable(m.ReturnType, emitter) ||
                           m.ReturnType.IsKnownType(KnownTypeCode.NullableOfT) &&
                           ConversionBlock.IsBoxable(NullableType.GetUnderlyingType(m.ReturnType), emitter);

            if (needBox)
            {
                StringBuilder sb = new StringBuilder("function (" + JS.Vars.V + ") { return ");

                sb.Append(JS.Types.Bridge.BOX);
                sb.Append("(" + JS.Vars.V + ", ");
                sb.Append(ConversionBlock.GetBoxedType(m.ReturnType, emitter));

                var inlineMethod = ConversionBlock.GetInlineMethod(emitter, CS.Methods.TOSTRING,
                                                                   emitter.Resolver.Compilation.FindType(KnownTypeCode.String), m.ReturnType, null);

                if (inlineMethod != null)
                {
                    sb.Append(", " + inlineMethod);
                }

                inlineMethod = ConversionBlock.GetInlineMethod(emitter, CS.Methods.GETHASHCODE,
                                                               emitter.Resolver.Compilation.FindType(KnownTypeCode.Int32), m.ReturnType, null);

                if (inlineMethod != null)
                {
                    sb.Append(", " + inlineMethod);
                }

                sb.Append(");");

                sb.Append("}");
                properties.Add(JS.Fields.BOX, new JRaw(sb.ToString()));
            }
        }