The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,322 other followers

Archive for the ‘C# 3.0’ Category

.NET/C#: two ways of creating an empty array

Posted by jpluimers on 2016/08/18

Empty arrays are not used often as arrays usually are about the presence data, not about the absence.

Here are two ways based on the int data type in C# (the original [WayBackexamples [WayBack] are using string, but since string itself is also a kind of array…):

Specify a size of zero:

int[] a = new int[0];

Specify an empty initialisation:

int[] a = new int[] { };

Though many people think arrays are a thing of the past, I think it is one of the first generic types and have their place. For one, enumerating over arrays using foreach is a lot faster in many environments than enumerating over other data types. Another thing is that the fixed nature of arrays can be very beneficial in setting constraints.

That’s why I like the balanced view from Eric Lippert [WayBack] in Arrays considered somewhat harmful – Fabulous Adventures In Coding – Site Home – MSDN Blogs [WayBack]

–jeroen

via:

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Development, Software Development | Leave a Comment »

C#, XSD.exe, xsd2code and generating nullable fields+properties from an XSD with and without Specified fields/properties

Posted by jpluimers on 2016/07/27

It comes down to these cases for XML elements having maxOccurs="1" (which the default for maxOccurs):

  1. adding nillable="true" will convert from a regular type to a nullable type.
  2. adding minOccurs="0" will add boolean …Specified properties in the generated C# for each element.
  3. you can have both nillable="true" and minOccurs="0" in an element which gets you a nullable type and a …Specified property.

Note I’m not considering fixed or default here, nor attributes (that have use instead of minOccurs/maxOccurs, but do not allow for nillable) nor larger values of maxOccurs (which both xsd.exe and xsd2code regard as unbounded).

From the above, XML has a richer type system than C#, so in XML there are subtle a differences between:

  1. an explicit nil in the XML element
  2. the XML element being absent
  3. the XML element being empty.

Hopefully later more text and examples to show how to actually work with this.

Delphi related to minOccurs:

Note that xsd2code.codeplex.com (unlike XmlGen#) has at least two forks at github:

From the specs:

–jeroen

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Conference Topics, Conferences, Development, Event, Software Development, XML, XML/XSD, XSD | Leave a Comment »

Easy way to generate “System.InvalidOperationException: Nullable object must have a value.”

Posted by jpluimers on 2016/07/07

Easy way to generate “System.InvalidOperationException: Nullable object must have a value.”.

using System;
public class Test
{
public static void Main()
{
int? nullableInt = null;
int nowInt = (int)nullableInt;
}
}

–jeroen

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Development, Software Development | Leave a Comment »

Writing tests for http / https request: Postman, SoapUI, Advanced REST client.

Posted by jpluimers on 2016/06/21

I’m using these Chrome Extensions for most of the http / https call mockups, and after that put them in SoapUI (which despite the name also does REST and has come a long way sinceSource: SoupUI – as sometimes that is the only thing that works):

You can get both Postman versions through GetPostman.com as well.

–jeroen

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, ASP.NET, C#, C# 3.0, C# 4.0, C# 5.0, Chrome, Communications Development, Development, Google, HTTP, Internet protocol suite, Power User, REST, Software Development, TCP | 1 Comment »

Did you know… How to change the build order for your solution? – #333 – Sara Ford’s Weblog – Site Home – MSDN Blogs

Posted by jpluimers on 2016/06/08

Boy I wish I had known this earlier. Like years ago…

In the Solution Explorer:

  1. Right Click Project
  2. Project Build Oder.
  3. Use the dialog to change the build order

It is next to the “Project Dependencies” in this image from Sara Ford:

Sara Ford: change

Sara Ford: change “Project Build Order”

In the resulting dialog, you can change the build order within your solution.

This can be very useful when – for various reasons – you cannot have Project Level dependencies for an assembly, but have to have Assembly Reference dependencies for individual assemblies.

At a client I bumped into this, and this dialog was a life saver for us.

Others have used it because some Visual Studio versions miscalculate the dependencies.

–jeroen

Did you know… How to change the build order for your solution? – #333 – Sara Ford’s Weblog – Site Home – MSDN Blogs.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Development, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio 2012, Visual Studio 2013, Visual Studio and tools | Leave a Comment »

 
<span>%d</span> bloggers like this: