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

Optional arguments are “sort-of” CLS-compliant. Methods with optional arguments are legal and can be successfully compiled with the CLSCompliant attribute, but callers of those methods don’t necessarily need to take account of the default parameter values or the optional attribute. (In which case those methods would behave in exactly the same way as standard methods, … Read more

Method Overriding and Optional Parameters

Okay, as there’s general interest, here’s a quick version: Console.WriteLine(one) This will use the WriteLine(object) overload, which will in turn execute the object.ToString() virtual method, overridden in One – hence the output of ToString override Console.WriteLine(one.ToString()) This will look at One and see which methods have newly declared methods – discounting overrides. There’s exactly one … Read more

Mutually exclusive powershell parameters

You can use the parameter attribute to declare multiple parameter sets. You then simply assign parameters that are mutually exclusive to different parameter sets. EDIT: This is also documented in ‘about_Functions_Advanced_Parameters’, under the section “ParameterSetName Named Argument”. This is how different sets of parameters is handled with cmdlets like Get-Random (which has mutually exclusive parameters): … Read more

What are options hashes?

Options hash is a nice concept enabled by a feature of ruby parser. Say, you have a method with some required arguments. Also you may pass some optional arguments. Over time you may add more optional arguments or remove old ones. To keep method declaration clean and stable, you can pass all those optional arguments … Read more

Is replacing an optional parameter with overloads a breaking change?

I thought that was a good question, so here goes my take. Using a quick client that does this: c1.Foo(1); c1.Foo(1, 2); When using optional parameter the client IL looks like: IL_0000: nop IL_0001: newobj instance void [ClassLibrary1]ClassLibrary1.Class1::.ctor() IL_0006: stloc.0 IL_0007: ldloc.0 IL_0008: ldc.i4.1 IL_0009: ldc.i4.5 IL_000a: callvirt instance void [ClassLibrary1]ClassLibrary1.Class1::Foo(int32, int32) IL_000f: nop IL_0010: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)