optional-parameters

ReSharper: Find Usages of an optional parameter

冷暖自知 提交于 2019-12-05 00:00:20
If I have a function with optional parameter, is there an easy way to find all the locations in my code that call that function and pass a value to that parameter? The function has many non-default parameters, so scanning the usual Find Usages results of places that call the function is problematic, as it trims the lines and I can't see if the optional parameter is used. With your cursor on the parameter, choose ReSharper | Inspect | Value Origin , or from the keyboard, Inspect This with Ctrl + Shift + Alt + A , then Value Origin . You will get an Inspection Results window with all the places

Mutually exclusive powershell parameters

天大地大妈咪最大 提交于 2019-12-04 23:51:30
SCENARIO I'm writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|bar] p1, p2 That reads as the user must give a value for "-foo" or "-bar" but can't give both together. EXAMPLE OF VALID INPUT cmdletname -foo xxx -p1 hello -p2 world cmdletname -bar yyy -p1 hello -p2 world EXAMPLE OF INVALID INPUT cmdletname -foo xxx -bar yyy -p1 hello -p2 world MY QUESTION My question is on how to do this in powershell so that it does all the checking for me - or if that is possible

Mixing optional parameters and params when can't simply overload

你说的曾经没有我的故事 提交于 2019-12-04 23:34:25
Similar to this question , I want to mix optional parameters with the params keyword, which of course creates ambiguity. Unfortunately, the answer of creating overloads does not work, as I want to take advantage of caller info attributes, like this: public void Info(string message, [CallerMemberName] string memberName = "", [CallerLineNumber] int lineNumber = 0, params object[] args) { _log.Info(BuildMessage(message, memberName, lineNumber), args); } Creating an overload without the optional parameters would change the call-site, preventing these particular parameters from working properly. I

How to pythonically have partially-mutually exclusive optional arguments?

拈花ヽ惹草 提交于 2019-12-04 18:48:42
问题 As a simple example, take a class Ellipse that can return its properties such as area A , circumference C , major/minor axis a/b , eccentricity e etc. In order to get that, one obviously has to provide precisely two of its parameters to obtain all the other ones, though as a special case providing only one parameter should assume a circle. Three or more parameters that are consistent should yield a warning but work, otherwise obviously raise an exception. So some examples of valid Ellipse s

VBA Function Optional parameters

余生颓废 提交于 2019-12-04 16:23:59
问题 I am calling a specific piece of code several times therefore I would like to use optional parameters. I can write something like: Public Sub main() strA = "A" 'Calling the function CalculateMe (strA) End Sub Public Sub CalculateMe(strA As String) Set rs = DB.OpenRecordset("tbl_A") rs.MoveFirst Do Until rs.EOF If rs.Fields(0) = strA Then dblA = rs.fields(2).Value End If rs.MoveNext Loop End Sub How can I change the function to hold more than 1 optional parameters? Something like: Public Sub

C# “Constant Objects” to use as default parameters

浪子不回头ぞ 提交于 2019-12-04 15:54:21
问题 Is there any way to create a constant object(ie it cannot be edited and is created at compile time)? I am just playing with the C# language and noticed the optional parameter feature and thought it might be neat to be able to use a default object as an optional parameter. Consider the following: //this class has default settings private const SettingsClass DefaultSettings = new SettingsClass (); public void doSomething(SettingsClass settings = DefaultSettings) { } This obviously does not

Ruby Optional Parameters and Multiple Parameters

房东的猫 提交于 2019-12-04 11:49:00
I am trying to set the first argument to a method as being optional, followed by any number of args. For example: def dothis(value=0, *args) The issue I am running into is that it doesn't seem like this is actually possible? When I call dothis("hey", "how are you", "good") I was hoping it would set value to default to 0, but instead it is just making value="hey" . Is there any way to accomplish this behavior? This is not possible directly in Ruby There are plenty of options though, depending on what you are doing with your extended params, and what the method is intended to do. Obvious choices

Function overloading vs Optional Parameters

情到浓时终转凉″ 提交于 2019-12-04 10:14:56
So I'm just thinking about function overloading... Overloaded methods share the same name but have a unique signature. The number of parameters, types of parameters or both must be different. A function can't be overloaded on the basis of a different return type alone. So in the following example, why overload setName rather than use optional parameters for the middle and last name values? class funOverload { public string name; //overloaded functions public void setName(string last) { name = last; } public void setName(string first, string last) { name = first + "" + last; } public void

Websphere Application Server 6.1 (localized): Override locale for console messages

假如想象 提交于 2019-12-04 09:03:14
I have installed RAD 7.5 (based on Eclipse Ganymede 3.4.0) in Spanish. I'm working with Websphere Application Server 6.1 (spanish too). The problem I have is that all console messages appear in Spanish, but translation is, in my personal opinion, quite poor (especially since even the console errors are displayed in Spanish and it's difficult to find documentation about exact error messages). I want to start the IDE in the original language (English) and I know that there is a command line switch -nl en that, placed beside eclipse executable path on program shortcut, serves for this purpose.

Is the new feature of C# 4.0 - “Optional Parameters” CLS-Compliant?

时光怂恿深爱的人放手 提交于 2019-12-04 08:51:40
问题 This new feature is really convenient. Lately I read the document of the "Microsoft All-In-One Code Framework", and it mentions that "Optional Parameters" is not CLS-Compliant. So I tested it by using "Optional Parameters" in a public API, and turned on FxCop, then I compiled and FxCop did not complain about anything. At the mean while, FxCop did report a warning when I add an API that has uint as its return type. So now I am confused, is "Optional Parameters" CLS-Compliant or not? And what's