C# 2.0 Methods

PowerDesigner models C# methods as operations.

For information about creating and working with operations, see Operations (OOM).

Method Properties

Method property sheets contain all the standard operation tabs along with the C# tab, the properties of which are listed below:

Property

Description

Compilation Unit

Specifies the compilation unit in which the method will be stored. This field is only available if the parent type is a partial type (allocated to more than one compilation unit).

Extern

Specifies the extern modifier for the method declaration.

New

Specifies the new modifier for the method declaration. When a class inherits from another class and contains methods with identical signature as in the parent class, this field is selected automatically to make the child method prevail over the parent method.

Override

Specifies the override modifier for the method declaration.

Unsafe

Specifies the unsafe modifier for the method declaration.

Virtual

Specifies the virtual modifier for the method declaration.

Scope

Specifies the scope of the method.

Base Initializer

Creates an instance constructor initializer of the form base, causing an instance constructor from the base class to be invoked.

In the following example, class B inherits from class A. You define a Base Initializer in the class B constructor, which will be used to initialize the class A constructor:



internal class B : A
 {
  public B(int x, int y) : base(x + y, x - y)
  {}
 }

This Initializer

Creates an instance constructor initializer, causing an instance constructor from the class itself to be invoked.

Constructors and Destructors

You design C# constructors and destructors by clicking the Add Default Constructor/Destructor button on the class property sheet Operations tab. This automatically creates a constructor with the Constructor stereotype, and a destructor with the Destructor stereotype. Both constructor and destructor are grayed out in the list, which means you cannot modify their definition.

Method Implementation

Class methods are implemented by the corresponding interface operations. To define the implementation of the methods of a class, you have to use the To be implemented button on the class property sheet Operations tab, then click the Implement button for each method to implement. The method is displayed with the <<Implement>> stereotype.

Operator Method

You design a C# operator using an operation with the <<Operator>> stereotype. Make sure the <<Operator>> operation has Public visibility and the Static property selected.

To define an external operator, you have to set the extern extended attribute of the operation to True. The new, virtual and override extended attributes are not valid for operators.

The operator token (like +, -, !, ~, or ++ for example) is the name of the method.



Conversion Operator Method

You design a C# conversion operator using an operation with the <<ConversionOperator>> stereotype.

You also need to declare the conversion operator using the explicit or implicit keywords. You define the conversion operator keyword by selecting the implicit or explicit value of the scope extended attribute.

In the following example, class Digit contains one explicit conversion operators and one implicit conversion operator:



public struct Digit
{
 public Digit(byte value)
  {
   if (value < 0 || value > 9) throw new ArgumentException();
   this.value = value;
  }
 public static implicit operator byte(Digit d)
 {
  return d.value;
 }
 
 public static explicit operator Digit(byte b)
  {
   return new Digit(b);
  }
 private byte value;
}