optional-parameters

SQL Server stored procedure parameters

血红的双手。 提交于 2019-11-27 05:33:21
问题 I am developing a framework, where in I am a calling stored procedure with dynamically created parameters. I am building parameter collection at the runtime. The problem occurs when I am passing a parameter to stored procedure, but stored proc doesn't accept such parameter. For example, my stored procedure is: CREATE PROCEDURE GetTaskEvents @TaskName varchar(50) AS BEGIN -- SP Logic END Calling stored procedure as: EXEC GetTaskEvents @TaskName = 'TESTTASK', @ID = 2 This throws below error:

How can I default a parameter to Guid.Empty in C#?

ぃ、小莉子 提交于 2019-11-27 05:17:36
问题 I wish to say: public void Problem(Guid optional = Guid.Empty) { } But the compiler complains that Guid.Empty is not a compile time constant. As I don’t wish to change the API I can’t use: Nullable<Guid> 回答1: Solution You can use new Guid() instead public void Problem(Guid optional = new Guid()) { // when called without parameters this will be true var guidIsEmpty = optional == Guid.Empty; } You can also use default(Guid) default(Guid) also will work exactly as new Guid() . Because Guid is a

Parameter Action<T1, T2, T3> in which T3 can be optional

拜拜、爱过 提交于 2019-11-27 04:35:54
I have the following code: public static MyMethod() { ...Do something ProtectedMethod(param1, param2); ...Do something } protected static void ProtectedMethod(IEnumerable<string> param1, string param2, int param3 = 1) { ... Do something } Take notice of the optional param3 parameter. Now for quite a few reasons I need to extract the code of the MyMethod method into its own class but I cannot extract ProtectedMethod with it because of all the classes that are inheriting from this one and I need to keep the changes small and isolated. So I figured I could have an Action<> delegate in the new

optional parameters in SQL Server stored proc?

北城余情 提交于 2019-11-27 04:27:12
I'm writing some stored procs in SQL Server 2008, and wondered if the concept of optional input parameters is possible here? I suppose I could always pass in NULL for parameters I don't want to use, check the value in the stored proc, then take things from there, but I was interested if the concept is available here. Thanks! You can declare like this CREATE PROCEDURE MyProcName @Parameter1 INT = 1, @Parameter2 VARCHAR (100) = 'StringValue', @Parameter3 VARCHAR (100) = NULL AS /* check for the NULL / default value (indicating nothing was passed */ if (@Parameter3 IS NULL) BEGIN /* whatever code

Parameter Action<T1, T2, T3> in which T3 can be optional

血红的双手。 提交于 2019-11-27 03:58:20
问题 I have the following code: public static MyMethod() { ...Do something ProtectedMethod(param1, param2); ...Do something } protected static void ProtectedMethod(IEnumerable<string> param1, string param2, int param3 = 1) { ... Do something } Take notice of the optional param3 parameter. Now for quite a few reasons I need to extract the code of the MyMethod method into its own class but I cannot extract ProtectedMethod with it because of all the classes that are inheriting from this one and I

How does one make an optional closure in swift?

不打扰是莪最后的温柔 提交于 2019-11-27 03:26:39
I'm trying to declare an argument in Swift that takes an optional closure. The function I have declared looks like this: class Promise { func then(onFulfilled: ()->(), onReject: ()->()?){ if let callableRjector = onReject { // do stuff! } } } But Swift complains that "Bound value in a conditional must be an Optional type" where the "if let" is declared. You should enclose the optional closure in parentheses. This will properly scope the ? operator. func then(onFulfilled: ()->(), onReject: (()->())?){ if let callableRjector = onReject { // do stuff! } } To make the code even shorter we can use

Calling Fortran subroutines with optional arguments from C++

妖精的绣舞 提交于 2019-11-27 03:26:01
问题 How would I reference a Fortran function in a C++ header that uses optional arguments? Would I have a prototype in the header for each possible combination of calls? Or is this even possible? For instance, Fortran: subroutine foo(a, b, c) bind(c) real, intent(in), optional :: a, b, c ... end subroutine foo 回答1: It is not possible, at least portably, unless you make the subroutine bind(C) . Once you make it bind(C) , it is just passing of a pointer which can be NULL on the C side. subroutine

Python: how to check whether optional function parameter is set

走远了吗. 提交于 2019-11-27 02:28:51
问题 Is there an easy way in Python to check whether the value of an optional parameter comes from its default value, or because the user has set it explicitly at the function call? 回答1: Lot of answers have little pieces of the full info, so I'd like to bring it all together with my favourite pattern(s). default value is a mutable type If the default value is a mutable object, you are lucky: you can exploit the fact that Python’s default arguments are evaluated once when the function is defined

Can I have an optional parameter for an ASP.NET SOAP web service

穿精又带淫゛_ 提交于 2019-11-27 02:08:34
I want to build a webservice with this signature, which does not throw an exception if param2 is left empty. Is this possible? [WebMethod] public string HelloWorld(string param1, bool param2) { } The exception is a System.ArgumentException that is thrown when trying to convert the empty string to boolean. Ideas that have not worked so far: method overloading is not allowed for webservices, like public string HelloWorld(string param1) { return HelloWorld(param1, false); } as suggested here : make bool nullable bool? . Same exception. manipulate the WSDL, see this answer My question is related

ASP.net MVC routing with optional first parameter

China☆狼群 提交于 2019-11-27 01:40:55
问题 I need to provide following functionality for one of the web sites. http://www.example.com/ [sponsor] /{controller}/{action} Depending on the [sponsor], the web page has to be customized. I tried combination of registering the routes with Application_Start and Session_Start but not able to get it working. public static void RegisterRoutes(RouteCollection routes, string sponsor) { if (routes[sponsor] == null) { routes.MapRoute( sponsor, // Route name sponsor + "/{controller}/{action}/{id}", //