FeResPost Web Site                     FeResPost Online User Manual

IX.1.4 Extending CLA classes

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

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

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

Note that the first argument is “this ClaMat m”, which indicates the class that is being extended. In file “NETEX/EX13/extendedCla.cs”, the extension methods are defined in “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 ruby corresponding ruby methods with ruby extension. For example, the following C# source lines take into account that “getPliesStresses” method of .NET assembly returns a 2D Array:

    ...  
    sigTab=l.getPliesStresses();  
    nbrLines=sigTab.GetLength(0);  
    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");  
    for (i=0;i<nbrLines;i++) {  
        os.Write("   {0,8}{1,5}",sigTab[i,0],sigTab[i,1]);  
        os.WriteLine("{0,14}{1,14}{2,14}",sigTab[i,2],  
                     sigTab[i,3],sigTab[i,7]);  
    }  
    os.Write("' n");  
    ...

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  
    ...