Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure why you want the as an interface as opposed to a regular class. Will other classes implement this interface, or are you just looking for a standard way to access the API?</p> <p>If you're just looking for a standard way to access the API, I'd suggest a variation on the builder pattern. The builder pattern is normally used for classes, but I don't see why it can't be used for methods as well. See <a href="http://cdmckay.org/blog/2009/07/03/joshua-blochs-builder-pattern-in-csharp/" rel="nofollow">http://cdmckay.org/blog/2009/07/03/joshua-blochs-builder-pattern-in-csharp/</a> for a couple class-based examples.</p> <p>Here's my attempt given what you supplied. I apologize if there are syntax errors, my editor at home is somewhat lacking...</p> <pre><code>public class AccessServiceAPI { private void MethodA(string mandatory, string mandatory2, string optional) { // do stuff } public class MethodABuilder { private string Mandatory { get; set; } private string Mandatory2 { get; set; } private string Optional { get; set; } public MethodABuilder( string mandatory, string mandatory2) { Mandatory = mandatory; Mandatory2 = mandatory; Optional = "default value"; } public MethodABuilder Optional( string optional ) { Optional = optional; return this; } public void Build() { MethodA(mandatory, mandatory2, optional); } } } </code></pre> <p>The client would then call the method like this:</p> <pre><code>MethodABuilder.Builder(mandatory, mandatory2).Optional(optional).Build(); </code></pre> <p>If they don't want to set a value for an optional parameter, they can just skip it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload