optional-parameters

js sort() custom function how can i pass more parameters?

ぃ、小莉子 提交于 2019-11-27 15:01:44
问题 I have an array of objects i need to sort on a custom function, since i want to do this several times on several object attributes i'd like to pass the key name for the attribute dinamically into the custom sort function: function compareOnOneFixedKey(a, b) { a = parseInt(a.oneFixedKey) b = parseInt(b.oneFixedKey) if (a < b) return -1 if (a > b) return 1 return 0 } arrayOfObjects.sort(compareByThisKey) should became something like: function compareOnKey(key, a, b) { a = parseInt(a[key]) b =

Web Service Method with Optional Parameters [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-11-27 13:45:55
问题 Possible Duplicate: Can I have an optional parameter for an ASP.NET SOAP web service I have tried looking around for this but I really cannot find the right solution for what I want to do. Sorry for the repetition since I know this has been asked before. I have a Web Service Method in which I want to have an optional parameter such as: public void MyMethod(int a, int b, int c = -3) I already know I cannot use nullable parameters, so I am just trying to use a default value. Problem is when I

maven command line how to point to a specific settings.xml for a single command?

懵懂的女人 提交于 2019-11-27 10:49:45
Is it possible to point to a specific settings file in order to override the default settings.xml being used by maven for a single command? Example: mvn clean install -Dparam # -> pass specific settings file path as param to override default "home/.m2/settings.xml" You can simply use: mvn --settings YourOwnSettings.xml clean install or mvn -s YourOwnSettings.xml clean install 来源: https://stackoverflow.com/questions/25277866/maven-command-line-how-to-point-to-a-specific-settings-xml-for-a-single-command

Optional dependencies in AngularJS

混江龙づ霸主 提交于 2019-11-27 10:14:57
问题 I'm trying to implement a controller in AngularJS which is used across multiple pages. It makes use of some services. Some of them are loaded on all pages, some - not. I mean it is defined in different files, and these files are loaded independently. But if I do not load these services on all pages I got error: Error: Unknown provider: firstOtionalServiceProvider <- firstOtionalService So, I need to load scripts on all pages. Can I declare dependency as optional in Angular? E.g: myApp

Ruby optional parameters

…衆ロ難τιáo~ 提交于 2019-11-27 09:22:27
问题 If I define a Ruby functions like this: def ldap_get ( base_dn, filter, scope=LDAP::LDAP_SCOPE_SUBTREE, attrs=nil ) How can I call it supplying only the first 2 and the last args? Why isn't something like ldap_get( base_dn, filter, , X) possible or if it is possible, how can it be done? 回答1: This isn't possible with ruby currently. You can't pass 'empty' attributes to methods. The closest you can get is to pass nil: ldap_get(base_dn, filter, nil, X) However, this will set the scope to nil,

How to create default value for function argument in Clojure

自作多情 提交于 2019-11-27 09:14:47
问题 I come with this: (defn string->integer [str & [base]] (Integer/parseInt str (if (nil? base) 10 base))) (string->integer "10") (string->integer "FF" 16) But it must be a better way to do this. 回答1: A function can have multiple signatures if the signatures differ in arity. You can use that to supply default values. (defn string->integer ([s] (string->integer s 10)) ([s base] (Integer/parseInt s base))) Note that assuming false and nil are both considered non-values, (if (nil? base) 10 base)

How to pass a nullable type to a P/invoked function [duplicate]

懵懂的女人 提交于 2019-11-27 09:05:20
This question already has an answer here: How do I handle null or optional dll struct parameters in C# 1 answer I have a few p/invoked functions (but I'm rewriting my code at the moment so I'm tidying up) and I want to know how to use/pass a nullable type as one of the parameters. working with int types isn't a problem but given the following: [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, int? enumerator, IntPtr hwndParent, uint Flags); I'd like to be able to pass the Guid parameter as a nullable type. As

Setting the default value of a C# Optional Parameter

余生长醉 提交于 2019-11-27 09:01:39
Whenever I attempt to set the default value of an optional parameter to something in a resource file, I get a compile-time error of Default parameter value for 'message' must be a compile-time constant. Is there any way that I can change how the resource files work to make this possible? public void ValidationError(string fieldName, string message = ValidationMessages.ContactNotFound) In this, ValidationMessages is a resource file. No, you will not be able to make the resource work directly in the default. What you need to do is set the default value to something like null and then do the

Optional parameters in managed C++/CLI methods

ぐ巨炮叔叔 提交于 2019-11-27 07:43:41
问题 How can I declare a managed method in C++/CLI that has an optional parameter when used from C#? I've decorated the parameter with both an Optional and a DefaultParameterValue attribute (see: How default parameter values are encoded), but only the Optional attribute seems to be honored. C++/CLI: public ref class MyClass1 { public: MyClass1([System::Runtime::InteropServices::Optional] [System::Runtime::InteropServices::DefaultParameterValue(2)] int myParam1) ↑ { System::Console::WriteLine

Is there any reason to declare optional parameters in an interface?

别等时光非礼了梦想. 提交于 2019-11-27 05:50:01
问题 You can declare optional parameters in an interface method but implementing classes are not required to declare the parameters as optional, as Eric Lippert explained. Conversely, you can declare a parameter as optional in an implementing class but not in the interface. So is there any reason to declare optional parameters in an interface? If not, why is it allowed? Examples: public interface IService1 { void MyMethod(string text, bool flag = false); } public class MyService1a : IService1 {