Can MethodParameters be optional?

  • 20 October 2011
  • 1 reply
  • 2 views

Badge

SmartObjects (and underlying ServiceBrokers) understand that some inputs are mandatory, some optional. To indicate the difference, the methods are decorated with string[] requiredproperties. Those properties which are not in that list are optional and may (or may not) be supplied, whether via SmartObject tester or programmatically.


Methods can also have parameters beyond SmarytObejct properties, those are decorated with Attibutes.Parameter attribute.


I am under impression that all parameters decorated with Attibutes.Parameters become mandatory. Is there a way to make them optional? I could not find any relvant remarks in the documentation.


1 reply

Badge +10

Hi,


ServiceObject properties are decorated with attributes which "expose" them to the SmartObject. However your method determines which properties are mandatory or required. Even if you have other properties defined, if they are not listed in the decoration of the method they will not be used as input or return properties and therefore not mandatory.


The properties defined in a specific method's requiredproperties collection are the only ones which will be required for that method. The properties listed in the inputproperties collection are all the possible input properties (some of which might be required).


For example, assume you have a GetList method with a ServiceObject containing four properties; ID, Name, Surname, Department. Assume your users can search by ID, Name, Surname or Department, but they should always supply a value for the Department field (because there are too many users to return all of them at once). Below is how you will configure this method's decoration


[Attributes.Method("GetList", MethodType.List, "GetList", "Get a list of Users",
            new string[] { "ID", "Name", "Surname", "Department" }, // Input properties
            new string[] { "Department" }, // Required properties        
            new string[] { "ID", "Name", "Surname", "Department" })] // Return properties


To illustrate this further, assume there is another property called "DateStarted" but this property is used by another method in your ServiceObject. This property will be decorated with an attribute but for the above GetList method this property will not be required or returned.


I hope the above made sense and could help!

Reply