This is a migrated thread and some comments may be shown as answers.

C# out parameter does not convert right into VB.NET

2 Answers 112 Views
Code Converter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matti
Top achievements
Rank 1
Matti asked on 06 Aug 2010, 10:09 PM
Hello,

I just encountered a problem with your Batch Converter concerning how the out-parameter of C# is converted into VB.NET.

Namely, I noticed that when in the C# method-calling there is out parameter included (for example):

     PrintControl(c, ParentControlPrinting.BeforeChilds, mp, x, y, ref extendedHeight, out scanForChildControls);

... then the corresponding conversion in VB.NET functions not right - because the Sub method that is being called should
have ByRef keyword for the corresponding  parameter (here scanForChildControls) to function properly - at least in
many cases. But your converter sets the keyword ByVal and ignores the out parameter.

Could this problem be solved?

Regards,

Matti Ylén

2 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 11 Aug 2010, 06:23 PM
As far as I'm aware, the SharpDevelop NRefactory engine (which we use for conversions) does not have support for converting the C# "out" keyword. It will, however, try to convert "ByRef" VB keywords to "ref" C# keywords in method declarations. For a quick test with the converter offered by SharpDevelop, you can follow this link:

http://codeconverter.sharpdevelop.net/SnippetConverter.aspx

We'll do some additional research, and if a solution can be found, we'll definitely update the converter. Thanks for highlighting the issue!

-Todd
0
Matti
Top achievements
Rank 1
answered on 14 Aug 2010, 05:46 PM
...Thanks Todd for your time with the issue.

I tested the SharpDevelop NRefactory engine via the link you provided and indeed encountered the same problem: out -parameter of C# is not converted into ByRef-keyword for the VB.Net's parameter definition in the sub procedure or function being called. But, as you said, the ref -paramteter of C#  is indeed converted correctly into ByRef. Below I give a piece of C# code to demostrate this for yourself:


        private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            _MultiPage.NewPage(ev.Graphics);
            Single extendedHeight;
            Single y;

            y = 0;
            extendedHeight = 0;
            bool scanForChildControls;
            if (DelegatePrintingReportTitle == null)
                PrintReportTitle(_f, ParentControlPrinting.BeforeChilds , _MultiPage, _xform, y, ref extendedHeight, out scanForChildControls);
            else
                DelegatePrintingReportTitle(_f, ParentControlPrinting.BeforeChilds , _MultiPage, _xform, y, ref extendedHeight, out scanForChildControls);
            y += extendedHeight;

            // Print each control on the form
            Single globalExtendedHeight;
            PrintControls(_f, _MultiPage, _xform, y, out globalExtendedHeight);

            if (_MultiPage.LastPage())
            {
                ev.HasMorePages = false;
                _MultiPage.ResetPage();
            }
            else
                ev.HasMorePages = true;
        }



public void PrintReportTitle(System.Windows.Forms.Control c,
            ParentControlPrinting typePrint,
            MultiPageManagement mp,
            Single x, Single y,
            ref Single extendedHeight, out bool ScanForChildControls)
        {
            ScanForChildControls = false;
            Font printFont = new Font(c.Font.Name, (Single) (c.Font.Size * 1.3), FontStyle.Bold);
            float fontHeight =  mp.FontHeight(printFont);
            Pen pen = new Pen(Color.Black, 2);
            extendedHeight = fontHeight + 3 + pen.Width + 1;

            mp.BeginPrintUnit(y, extendedHeight);
            mp.DrawString(c.Text, printFont, Brushes.Black, x, y, c.Width, fontHeight);
            y += fontHeight + 3;
            mp.DrawLines(pen, x, y, x + c.Size.Width, y);
            mp.EndPrintUnit();
        }

Regards,

Matti Ylén
Tags
Code Converter
Asked by
Matti
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Matti
Top achievements
Rank 1
Share this question
or