named-parameters

How to define named Parameters C#

妖精的绣舞 提交于 2019-12-01 02:24:36
This seems like a simple question, but for some reason I can't find the answer anywhere. Basically, I'd like to be able to implement a constructor that takes NamedParameters . By named parameters, I do not mean parameters with default values (optional parameters) such as: public SomeMethod(){ string newBar = Foo(bar2 : "customBar2"); } public string Foo(string bar1 = "bar1", bar2 = "bar2" ){ //... } A good example of what I'm trying to achieve is the AuthorizeAttribute from the System.Web.Mvc assembly. Which you can use the following way: [Authorize(Roles = "Administrators", Users =

Named function parameters in PHP

Deadly 提交于 2019-11-30 17:49:10
Is it possible in php like in python to have named function parameters? An example use case is: function foo($username = "", $password = "", $timeout = 10) { } I want to override $timeout : foo("", "", 3); Ugly. I would much rather do: foo(timeout=3); No, named parameters are not possible in PHP. Technically when you call foo($timeout=3) it is evaluating $timeout=3 first, with a result of 3 and passing that as the first parameter to foo() . And PHP enforces parameter order, so the comparable call would need to be foo("", "", $timeout=3) . You have two other options: Have your function take an

How to perform batch update in Spring with a list of maps?

老子叫甜甜 提交于 2019-11-30 17:39:05
New to Spring, I am trying to insert a List<Map<String, Object>> into a table. Until now I have been using the SqlParameterSource for batch update, which works fine when a java bean is supplied to them. Something like this: @Autowired private NamedParameterJDBCTemplate v2_template; public int[] bulkInsertIntoSiteTable(List<SiteBean> list){ SqlParameterSource[] batch = SqlParameterSourceUtils .createBatch(list.toArray()); int[] updateCounts = v2_template .batchUpdate( "insert into sitestatus (website, status, createdby) values (:website, :status, :username)", batch); return updateCounts; }

Named/optional parameters in Delphi?

余生长醉 提交于 2019-11-30 08:06:31
问题 In one of the Delphi demo applications, I've stumbled upon some syntax that I didn't know the Delphi compiler accepted: // ......\Demos\DelphiWin32\VCLWin32\ActiveX\OleAuto\SrvComp\Word\ // Main.pas, line 109 Docs.Add(NewTemplate := True); // note the assignment I can't seem to reproduce this type of parameter passing in my own code, and I never see anyone use it. So these are my questions: Can i use this in "normal" methods and is it part of "the Delphi Language", or is this some compiler

No named parameters in Ruby?

南笙酒味 提交于 2019-11-30 06:23:11
问题 This is so simple that I can't believe it caught me. def meth(id, options = "options", scope = "scope") puts options end meth(1, scope = "meh") -> "meh" I tend to use hashes for argument options just because it was how the herd did it– and it is quite clean. I thought it was the standard. Today, after about 3 hours of bug hunting, I traced down an error to this gem I happen to be using that assumes named parameters will be honored. They are not. So, my question is this: Are named parameter

Named Parameters in Ruby Structs

☆樱花仙子☆ 提交于 2019-11-30 05:44:52
I'm pretty new to Ruby so apologies if this is an obvious question. I'd like to use named parameters when instantiating a Struct, i.e. be able to specify which items in the Struct get what values, and default the rest to nil. For example I want to do: Movie = Struct.new :title, :length, :rating m = Movie.new :title => 'Some Movie', :rating => 'R' This doesn't work. So I came up with the following: class MyStruct < Struct # Override the initialize to handle hashes of named parameters def initialize *args if (args.length == 1 and args.first.instance_of? Hash) then args.first.each_pair do |k, v|

How to perform batch update in Spring with a list of maps?

我是研究僧i 提交于 2019-11-30 01:37:32
问题 New to Spring, I am trying to insert a List<Map<String, Object>> into a table. Until now I have been using the SqlParameterSource for batch update, which works fine when a java bean is supplied to them. Something like this: @Autowired private NamedParameterJDBCTemplate v2_template; public int[] bulkInsertIntoSiteTable(List<SiteBean> list){ SqlParameterSource[] batch = SqlParameterSourceUtils .createBatch(list.toArray()); int[] updateCounts = v2_template .batchUpdate( "insert into sitestatus

Named function parameters in PHP

帅比萌擦擦* 提交于 2019-11-30 01:11:48
问题 Is it possible in php like in python to have named function parameters? An example use case is: function foo($username = "", $password = "", $timeout = 10) { } I want to override $timeout : foo("", "", 3); Ugly. I would much rather do: foo(timeout=3); 回答1: No, named parameters are not possible in PHP. Technically when you call foo($timeout=3) it is evaluating $timeout=3 first, with a result of 3 and passing that as the first parameter to foo() . And PHP enforces parameter order, so the

Should I call Parameters.Clear when reusing a SqlCommand with a transation?

老子叫甜甜 提交于 2019-11-29 10:21:47
I'm coding a transaction manually in ADO.NET. The example I'm working from reuses the SqlCommand which seem like a fine idea. However, I have added parameters to my command. My question is: in the following code, is command.Parameters.Clear() correct? Or am I doing it wrong? using (var connection = new SqlConnection(EomAppCommon.EomAppSettings.ConnStr)) { connection.Open(); SqlTransaction transaction = connection.BeginTransaction(); SqlCommand command = connection.CreateCommand(); command.Transaction = transaction; try { foreach (var itemIDs in this.SelectedItemIds) { command.CommandText =

Named and optional parameters, and WCF

大兔子大兔子 提交于 2019-11-29 09:09:04
so .Net 4 added named and optional parameters which are pretty sweet. I don't need to make as many 1 line overload methods. Will that work over WCF? Since these are compiler semantics I'd say no. However you'd expect them to work in the only following way. On the Service Code side all code would accept the defaulted parameters. On the client side I note that the 'Add Service Reference' tooling on VS2010 doesn't take the defaults and add them to the generated proxy. So You'd have to generate you're own proxy. In this way the client code can use the defaults if the the default is specified in