FeResPost Web Site                     FeResPost Online User Manual

IX.1.4 Extending CLA classes

The examples provided in “NET/EX13” illustrate the possibility of extending FeResPost classes in C# by defining “extension” methods. Note, however, that this capability exists only if version 3 or above of the C# compiler is used.

In the following example, extracted from “NET/EX13/extendedCla.cs”, the ClaMat class is extended with the method “write_Compliance”:

namespace extension {
    static class ext {
        ...
        public static void write_Compliance(this ClaMat mat, TextWriter os, float theta) {
            writeMat(os, mat.getCompliance(theta));
        }
        ...

Note that the first argument is “this ClaMat mat”, which indicates the class that is being extended. In the file “NET/EX13/extendedCla.cs”, the extension methods are defined in the “extension” namespace. A “using extension” statement must be present in the client program to access the extensions.

Note also that many of the methods defined in C# differ from the corresponding methods in the Ruby extension. For example, the following C# source lines take into account that the “getPliesStresses” method of the .NET assembly returns a 2D Array:

    ...
    object[,] sigTab = lam.getPliesStresses();
    os.Write("   {0,8}{1,5}", "layer", "loc");
    os.Write("{0,14}{1,14}{2,14}", "sig_11", "sig_22", "sig_12");
    os.Write("\n");
    int nbrRows = epsTab.GetLength(0);
    for (int i = 0; i < nbrRows; i++)
    {
        object[] sigRow = Util.getDataRow(sigTab, i);
        os.Write("{0,14:G6}{1,14:G6}{2,14:G6}", sigRow[2], sigRow[3], sigRow[7]);
        os.Write("\n");
    }
    ...

The Ruby extension returns an Array of Arrays, and the corresponding lines would be:

    ...
    sigTab=getPliesStresses
    os.printf("   %8s%5s","layer","loc")
    os.printf("%14s%14s%14s","sig_11","sig_22","sig_12")
    os.printf("\n")
    (0...sigTab.size).each do |i|
        os.printf("   %8d%5s",sigTab[i][0],sigTab[i][1])
        os.printf("%14g%14g%14g",sigTab[i][2],sigTab[i][3],
                  sigTab[i][7])
        os.printf("\n")
    end
    ...