Brackets for functions in CSharp Methods - why so unusual?

Hi, Does anyone have any idea why I need to put curly braces on functions in CSharp methods as follows for methods to work?
Aras.IOM.Innovator innovator = this.getInnovator();
Item controlledItem = this.newItem(this.getAttribute("type"), "labs_GetControlledItemCSharp");
controlledItem.setID(this.getID());
controlledItem = controlledItem.apply();
return exampleFunction(controlledItem);

} // here I need to use a closing bracket!

Item exampleFunction (Item target) {
   return target;
// no closing bracket!
Is this normal CSharp behaviour? Maybe that's something obvious for professional programmers - but I'm not one :-). So I would be glad for any hints. Thank´s in advance!
  • Hello, I can confirm that this odd bracketing is because of a quirk with how CSharp methods are compiled in Aras Innovator. This is not standard behavior for CSharp outside of Aras Innovator. You can imagine that any CSharp method code you write is compiled inside of another function like so:
    Item internalArasFunction(Item context) {
    // <-- Your code is inserted here
    }
    Using this example, the need for the initial closing bracket is to close the internalArasFunction method like this:
    Item internalArasFunction(Item context) {
    
    Aras.IOM.Innovator innovator = this.getInnovator();
    Item controlledItem = this.newItem(this.getAttribute("type"), "labs_GetControlledItemCSharp");
    controlledItem.setID(this.getID());
    controlledItem = controlledItem.apply();
    return exampleFunction(controlledItem);
    } // <-- The closing bracket of your method
    
    } // <-- Now this is bracket is hanging because there's no matching opening bracket
    As you can see in the above example, there is now a bracket that does not have a matching opening bracket. This bracket is why you need to leave off the closing bracket of the last function you define in your CSharp Method within Aras:
    Item internalArasFunction(Item context) {
    
    Aras.IOM.Innovator innovator = this.getInnovator();
    Item controlledItem = this.newItem(this.getAttribute("type"), "labs_GetControlledItemCSharp");
    controlledItem.setID(this.getID());
    controlledItem = controlledItem.apply();
    return exampleFunction(controlledItem);
    }
    
    Item exampleFunction (Item target) {
    return target;
    // <-- No closing bracket for this function within Innovator...
    
    } // <-- ...because it already exists here when it is compiled
    I hope this explanation has helped make this quirky behavior a little more clear! Chris
    Christopher Gillis Aras Labs Software Engineer
  • Hi Chris, Thanks for the detailed explanation! As long as my code works, I'm not bothered by such litte quirks. Best regards, Angela