optional-parameters

WCF and optional parameters

你离开我真会死。 提交于 2019-11-29 01:23:15
I just started using WCF with REST and UriTemplates. Is it now possible to use optional parameters? If not, what would you guys recommend I do for a system that has three parameters that are always used in the url, and others that are optional (varying amount)? Example: https://example.com/?id=ID&type=GameID&language=LanguageCode&mode=free id, type, language are always present mode is optional I just tested it with WCF 4 and it worked without any problems. If I don't use mode in query string I will get null as parameter's value: [ServiceContract] public interface IService { [OperationContract]

Guava Optional as method argument for optional parameters

二次信任 提交于 2019-11-29 00:39:24
Recently I had a discussion with my teammate on use of Guava Optional for optional parameters in a method. Let's say method is List<Book> getBooks(String catalogId, Optional<String> categoryId) { Validate.notNull(catalogId); Validate.notNull(categoryId); // Point of conflict. Is this required? which accepts a catalogId and an optional categoryId which returns books listed in that catalog and if category is also passed then returns books only in that category. Point of conflict was, Validating Optional<String> categoryId for null check. I was of view point that there should not be a null check

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

天涯浪子 提交于 2019-11-28 23:44:22
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 = parseInt(b[key]) if (a < b) return -1 if (a > b) return 1 return 0 } arrayOfObjects.sort(compareOn(

Passing in NULL as a parameter in ES6 does not use the default parameter when one is provided

雨燕双飞 提交于 2019-11-28 23:36:03
问题 Is there a known reason why passing in null as a parameter in ES6 does not use the default parameter when one is provided? function sayHello(name = "World") { console.log("Hello, " + name + "!"); } sayHello("Jim"); // Hello, Jim! sayHello(undefined); // Hello, World! sayHello(null); // Hello, null! 回答1: This is not that obvious I've read some comments of why undefined is completely different than null and that's why it explains the current behavior of default parameters. One could argue that

Optional Template parameter

心已入冬 提交于 2019-11-28 22:41:57
Is it possible to have optional template parameter in C++ , for example template < class T, class U, class V> class Test { }; Here I want user to use this class either with V or without V Is following possible Test<int,int,int> WithAllParameter Test<int,int> WithOneMissing If Yes how to do this. You can have default template arguments, which are sufficient for your purposes: template<class T, class U = T, class V = U> class Test { }; Now the following work: Test<int> a; // Test<int, int, int> Test<double, float> b; // Test<double, float, float> Sure, you can have default template parameters:

How do optional Parameters in Let/Get Properties work?

冷暖自知 提交于 2019-11-28 20:47:13
I am using vba with Excel 2007, and am writing code for a class module. 1) Is the following code even possible?... Essentially I have two enums, call them eDATASET and eDATATSUBSET . A particular value from eDATASET should trigger an assignment from the optionally passed parameter in a Let property. Something like this: Public Property Let foo(Optional ByVal lngSubSet as eDATASUBSET, _ ByVal lngSuperSet as eDATASET) Select Case lngSuperSet Case eDATASET.abc, eDATASET.def mlngBar = lngSuperSet Case eDATASET.xyz '// if lngSubSet not passed, trigger error code... mlngBar = lngSubSet End Select

The compiler is complaining about my default parameters?

无人久伴 提交于 2019-11-28 18:36:13
问题 I'm having trouble with this piece of code , after i took this class from the main.cpp file and splitted it in to .h and .cpp the compiler started complaining about the default parameters i was using in a void. /* PBASE.H */ class pBase : public sf::Thread { private: bool Running; public: sf::Mutex Mutex; WORD OriginalColor; pBase(){ Launch(); Running = true; OriginalColor = 0x7; } void progressBar(int , int); bool key_pressed(); void setColor( int ); void setTitle( LPCWSTR ); bool test

Optional dependencies in AngularJS

妖精的绣舞 提交于 2019-11-28 17:10:44
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.controller('MyController', ['$scope', 'firstRequiredService', 'secondRequiredService', 'optional

Are Options and named default arguments like oil and water in a Scala API?

半城伤御伤魂 提交于 2019-11-28 16:40:13
I'm working on a Scala API (for Twilio, by the way) where operations have a pretty large amount of parameters and many of these have sensible default values. To reduce typing and increase usability, I've decided to use case classes with named and default arguments. For instance for the TwiML Gather verb: case class Gather(finishOnKey: Char = '#', numDigits: Int = Integer.MAX_VALUE, // Infinite callbackUrl: Option[String] = None, timeout: Int = 5 ) extends Verb The parameter of interest here is callbackUrl . It is the only parameter which is really optional in the sense that if no value is

Ruby optional parameters

馋奶兔 提交于 2019-11-28 15:45:34
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? 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, not LDAP::LDAP_SCOPE_SUBTREE. What you can do is set the default value within your method: def ldap_get(base