default-value

Using XML decorations to specify default values during de-serialization

久未见 提交于 2020-06-09 16:57:11
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the

Using XML decorations to specify default values during de-serialization

好久不见. 提交于 2020-06-09 16:56:09
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the

Using XML decorations to specify default values during de-serialization

亡梦爱人 提交于 2020-06-09 16:56:07
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the

Function that takes an object with optional/default properties as a parameter?

北战南征 提交于 2020-02-14 06:51:12
问题 I understand that, using ES6 syntax, a function can be made that takes an object as a parameter and that parameter can have a default value, like so: function exampleFunction(objParam = {val1: 1, val2: 2}) { //... } If I call exampleFunction() , objParam is given the default value. However, if I call exampleFunction({val1: 3}) , objParam.val2 is undefined . This makes sense, because the default isn't being applied. Is there any way I can make sure that objParam.val2 does have a value, using

Function that takes an object with optional/default properties as a parameter?

一个人想着一个人 提交于 2020-02-14 06:50:33
问题 I understand that, using ES6 syntax, a function can be made that takes an object as a parameter and that parameter can have a default value, like so: function exampleFunction(objParam = {val1: 1, val2: 2}) { //... } If I call exampleFunction() , objParam is given the default value. However, if I call exampleFunction({val1: 3}) , objParam.val2 is undefined . This makes sense, because the default isn't being applied. Is there any way I can make sure that objParam.val2 does have a value, using

Function that takes an object with optional/default properties as a parameter?

别来无恙 提交于 2020-02-14 06:49:27
问题 I understand that, using ES6 syntax, a function can be made that takes an object as a parameter and that parameter can have a default value, like so: function exampleFunction(objParam = {val1: 1, val2: 2}) { //... } If I call exampleFunction() , objParam is given the default value. However, if I call exampleFunction({val1: 3}) , objParam.val2 is undefined . This makes sense, because the default isn't being applied. Is there any way I can make sure that objParam.val2 does have a value, using

Python (3.6.3) argparse: default value of optional parameter to be another parameter's value

旧城冷巷雨未停 提交于 2020-02-06 07:58:50
问题 I have a function that takes as parameters an input folder (required) and output folder (optional), but I want the default value of the (optional) output folder to be the input folder. I can do this of course using, e.g. p = argparse.ArgumentParser(description="blah") p.add_argument('inpath', type=str, help="Path to input") p.add_argument('--outpath', required=False, type=str, help="Path to output") argin = p.parse_args() if argin.outpath is None: argin.outpath = argin.inpath but I want to

How do I set a default value for a new column using EF6 migrations?

倾然丶 夕夏残阳落幕 提交于 2020-02-06 04:42:42
问题 I know that you can manually manipulate the EF generated migration file to add in the 'defaultValue: 1' parameter to the 'AddColumn' method, but it does not seem to be generating the correct Oracle translation when I look at the generated script. See my EF migration 'Up' method below: public override void Up() { AddColumn("TABLE", "NEW_COLUMN", c => c.Decimal(nullable: false, precision: 10, scale: 0, defaultValue: 1)); } And after running 'update-database -script' I get the following

How to elegantly return an object that is default-initialized?

心已入冬 提交于 2020-01-29 06:53:50
问题 I have a class like below: class VeryVeryVeryLongTypeName { bool is_ok; VeryVeryVeryLongTypeName() : is_ok(false) {} }; VeryVeryVeryLongTypeName f() { VeryVeryVeryLongTypeName v; ... // Doing something if (condition_1 is true) { return v; } else { return VeryVeryVeryLongTypeName(); } ... // Doing something if (condition_2 is true) { return v; } else { return VeryVeryVeryLongTypeName(); } } I think the statement return VeryVeryVeryLongTypeName(); is very tedious and ugly, so, my question is:

How to elegantly return an object that is default-initialized?

▼魔方 西西 提交于 2020-01-29 06:51:45
问题 I have a class like below: class VeryVeryVeryLongTypeName { bool is_ok; VeryVeryVeryLongTypeName() : is_ok(false) {} }; VeryVeryVeryLongTypeName f() { VeryVeryVeryLongTypeName v; ... // Doing something if (condition_1 is true) { return v; } else { return VeryVeryVeryLongTypeName(); } ... // Doing something if (condition_2 is true) { return v; } else { return VeryVeryVeryLongTypeName(); } } I think the statement return VeryVeryVeryLongTypeName(); is very tedious and ugly, so, my question is: