c# method with several functions

Hi there, I am trying to make a recursive method in c# to process some relationships in my product structure which is based on several itemTypes. To do this I made different functions which are first called from a main. The only way I found to get the compiler to stop complain about CS0161 is to start the method like this:
return this;
}
public Item main()
{
Innovator inn = this.getInnovator();
etc.
and to remove the last } at the end of the method (I put the main first, then the functions, so I removed the } of the last function) But now I can see (with the help of visual studio) that my method is not running at all, it ends at the first } (the second line of the method). Is someone experienced with c# functions into Aras methods?
  • Hello, When creating a new Method item, you do not need to include a specific call to a 'main' function. When you attach the Method code to a server event, the code will be run whenever that event triggers. For example, the code in a Method that is attached to an onBeforeUpdate server event of the Part ItemType will run everytime that a Part item is updated by a user. As in your use case, sometimes it is helpful to break the code down into multiple functions when you have a lot of logic being run in a single server event. As you found, you can include additional functions within a Method item by first closing the primary code with a closing bracket '}' and leaving the closing bracket off of the last helper function you define as seen in the example below.
    Innovator inn = this.getInnovator();
    
    Item res = helperFunction(this);
    Item secRes = secondHelperFunction(this);
    Item lastRes = lastHelperFunction(this);
    
    return this;
    }
    
    public Item helperFunction(Item arg) {
    // Helper code
    return arg;
    }
    
    public Item secondHelperFunction(Item arg) {
    // Helper code
    return arg;
    }
    
    public Item lastHelperFunction(Item arg) {
    // Helper code
    return arg;
    In order to get the function in your example to run, you should include a call to it before the first closing bracket:
    main();
    return this; }
    public Item main()
    {
    Innovator inn = this.getInnovator();
    etc.
    Chris ____________________________________ Christopher Gillis Aras Labs Software Engineer
  • Thank you so much Christopher, My code now runs! Best regards