coding style - proper way to create Overload methods in api C# -
this question in regards proper , acceptable coding practice given following scenario.
i have following 2 methods.
public tservice getduplexclientchannel<t>(bindingtype bindingtype, endpointaddress endpointaddress) t : tservice { .. work .. .. return instanceof(tservice); } public tservice getduplexclientchannel<t>(bindingtype bindingtype, string endpointaddress) t : tservice { // call above method , return it. return getduplexclientchannel<t>(bindingtype, new endpointaddress(endpointaddress);
}
in first example have method work, , method b overload of a, calls work.
i know if acceptable pattern , or should code repeated in second method? best practice this.
i have looked @ link not answer question proper or not proper: better way overload methods in c#
yes, absolutely acceptable pattern since in case, generic argument seems unrelated type of endpoint address.
it seen in variety of libraries , frameworks such .net framework (console.write
) or following dapper source:
public static task<ienumerable<object>> queryasync(this idbconnection cnn, type type, commanddefinition command) { return queryasync<object>(cnn, type, command); }
Comments
Post a Comment