Bean-Style Properties 

Bean-style properties use the naming pattern used by Java Beans.

Remarks

There are two distinct naming patterns that may be used interchangeably in J# code to declare properties: the .NET naming pattern uses the get_ and set_ prefixes, and the bean naming pattern using get, set, and is as prefixes. To declare a bean-style property, use the /** @beanproperty */ tag instead of the /** @property */ tag to indicate the accessor uses the bean naming pattern. The compiler will look for the accessor to start with get, set, or is. The compiler will deduce the property name from the remainder of the identifier following the get, set, or is prefix. The case of the first letter in the property name is converted to lower case unless the property is in all caps, as per the camel casing convention applicable to methods in Java.

Example 1

The following example shows the definition of the /** @beanproperty */ tag to declare a property called value and the consumption of the property in C#.

// beanprop1.jsl
// compile with: /target:module
public class SimpleProperty
{
  /** @beanproperty */
  public int getvalue() { return _value; }

  /** @beanproperty */
  public void setvalue (int v) { _value = v; }

  private int _value;
}

// bpconsume.cs
// compile with: /addmodule:beanprop1.netmodule /platform:x86
class CMain
{
  public static void Main()
  {
     SimpleProperty simple = new SimpleProperty();
     simple.value = 15;
     System.Console.WriteLine( simple.value );
  }
}

Output

15

Example 2

The following example shows the use of the /** @beanproperty */ tag to declare a boolean property called initialized.

// beanprop2.jsl
// compile with: /target:module
/* Declare a read-only boolean bean property using
   the isXXXX pattern */

class BooleanProperty
{
   private boolean _init = false;

   /** @beanproperty */
   public boolean isinitialized()
   {
      return _init;
   }

   public void Initialize()
   {
      _init = true;
   }
}

// bpconsume2.cs
// compile with: /addmodule:beanprop2.netmodule /platform:x86
using System;

class CMain
{
   public static void Main()
   {
       BooleanProperty bp = new BooleanProperty();
       Console.WriteLine("Initialized: {0}", bp.initialized) ;
       bp.Initialize();
       Console.WriteLine("Initialized: {0}", bp.initialized) ;
   }
}

Output

Initialized: False
Initialized: True

See Also

Reference

Defining and Using Properties