Convert C# Properties to Java Online using CodePortingC#2Java App

Discussion in 'Programming' started by zarfishsn, Aug 1, 2012.

  1. #1
    CodePorting C#2Java engine allows all C# developers to automatically convert C# constructs to Java code which you do not find in Java by using auto-generated code. There are properties in C# which provide flexible mechanism to read, write or compute the values of private fields. These properties are also called accessors but there are no such C# equivalent properties in Java. While translating code, CodePorting C#2Java engine intelligently generates Java code to provide same functionality as provided by accessors.

    Following example shows migration of C# properties in java:

    [B]C# Code:[/B]
    
    namespace CSharp2java.Tests.Convert.Properties
    {
        internal [B]class[/B] Test151 : Test15
        {
            internal [B]void[/B] Method()
            {
                base.Property = 1;
                [B]int[/B] i = base.Property;
                base.Property += 20;
                base.Property++;
                --base.Property;
            }
        }
     
        [B]public[/B] [B]class[/B] Test15
        {
            [B]public[/B] [B]int[/B] Property
            {
                get { [B]return[/B] mProperty; }
                set { mProperty = value; }
            }
     
            [B]private[/B] [B]int[/B] mProperty;
        }
    } 
     
    [B]Java code generated by CodePorting:[/B]
    
     
    
    [B]package[/B] CSharp2java.Tests.Convert.Properties;
     
    [I]// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********[/I]
     
    [B]class[/B] Test151 [B]extends[/B] Test15
    {
        [B]void[/B] method()
        {
            [B]super[/B].setProperty(1);
            [B]int[/B] i = [B]super[/B].getProperty();
            [B]super[/B].setProperty([B]super[/B].getProperty() + 20);
            [B]super[/B].setProperty([B]super[/B].getProperty() + 1)[I]/*Property++*/[/I];
            [B]super[/B].setProperty([B]super[/B].getProperty() - 1)[I]/*--Property*/[/I];
        }
    }
     
    [B]public[/B] [B]class[/B] Test15
    {
        [B]public[/B] [B]int[/B] getProperty() { [B]return[/B] mProperty; }
        [B]public[/B] [B]void[/B] setProperty([B]int[/B] value) { mProperty = value; }
     
        [B]private[/B] [B]int[/B] mProperty;
    } 
    Code (markup):
    The Above Java code replicates the functionality of C# Properties through CodePorting C#2Java Engine.
     
    zarfishsn, Aug 1, 2012 IP