Multi-Part Method Names

In order to fit in well with the API conventions on the Cocoa platform, C# method syntax has been expanded with support for what we call multi-part method names.

Multi-part method names are essentially the ability for a method's name to be split into separate parts, each followed by a distinct parameter. This is "required" on the Cocoa platform, because all the platform's APIs follow this convention, and we wanted RemObjects C# to be able to both consume and implement methods alongside those conventions without resorting to awkward attributes or other adornments, and to feel at home on the Cocoa platform.

For cross-platform completeness, multi-part method names are now supported on all platforms, and are also compatible with Oxygene and Swift.

A multi-part method has parameter parts for each part, both when being declared:

bool application(UIApplication application) didFinishLaunchingWithOptions(NSDictionary launchOptions) { ... }

and when being called:

myClass.application(myapp) didFinishLaunchingWithOptions(options);

Implementing Multi-Part Constructors

RemObjects C# has always had the ability to call named and multi-part-named constructors defined externally, both from Cocoa APIs and on classes defined in Oxygene or Silver. With version 8.2, named constructors can now be declared and implemented in C# as well. To avoid ambiguity, the syntax for this deviates sightly from C#'s regular syntax for nameless constructors (which use the class's name), and uses the this keyword instead.

For example:

public class Foo
{
    public Foo(string name) // regular nameless C# constructor
    {
    }

    public this(string name) // same as above
    {
    }

    public this withName(string name) // regular named C# constructor
    {
    }

    public this withName(string name) andValue(object value) // multi-part C# constructor
    {
    }

}

These can be of course called as follows:

new Foo("Hello");
new Foo withName("Hello");
new Foo withName("Hello") andValue(42);

Version Notes

  • The ability to define custom multi-part constructors is new in Version 8.2.

See Also