Upgrading Interfaces with Optional Arguments

    The current C# generation capability has a feature for methods with optional arguments. They are converted to a series of overloaded methods with a different signature to simulate the optional arguments functionality.

    This feature is taken into account when an interface and implementing class is being upgraded too. It means all the overloaded methods must be generated in order to accomplish a complete implementation in the interface and implementing class code.

    This feature doesn’t apply for Visual Basic because optional arguments are supported in Visual Basic .NET and Visual Basic 6 alike.

    Original VB6 code

    AnInterface.cls
    
    Public Sub AMethod(Optional arg1 As Integer = 0, Optional arg2 As String = "")
    End Sub
    
    AClass.cls
    
    Public Sub AnInterface_AMethod(Optional arg1 As Integer = 0, Optional arg2 As String = "")
    ' Code
    End Sub
    

    VBUC resulting C#.NET code

    AnInterface.cls
    
        interface AnInterface
        {
            void  AMethod(ref  int arg1, ref  string arg2);
            void  AMethod(ref  int arg1);
            void  AMethod();
        } 
        internal class AnInterface_CoClass
        : AnInterface
        {
            public void  AMethod(ref  int arg1, ref  string arg2)
            {
            }
            public void  AMethod(ref  int arg1)
            {
                string tempRefParam = "";
                AMethod(ref arg1, ref tempRefParam);
            }
            public void  AMethod()
            {
                int tempRefParam2 = 0;
                string tempRefParam3 = "";
                AMethod(ref tempRefParam2, ref tempRefParam3);
            }
        }
    
    AClass.cls
    
        internal class AClass
        : AnInterface
        {
            public void  AMethod(ref  int arg1, ref  string arg2)
            {
                // Code
            }
            public void  AMethod(ref  int arg1)
            {
                string tempRefParam = "";
                AMethod(ref arg1, ref tempRefParam);
            }
            public void  AMethod()
            {
                int tempRefParam2 = 0;
                string tempRefParam3 = "";
                AMethod(ref tempRefParam2, ref tempRefParam3);
            }
        }

    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration