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 1,830 other subscribers

Archive for the ‘.NET’ Category

PowerShell: Do not take a shortcut while testing NULL values.

Posted by jpluimers on 2014/03/05

A while ago I found a blog post explaining how to shortcut testing NULL values with PowerShell.

Do not do that!

I agree with the quote on the blog:

One thing you may not forget is that Powershell is a lot more friendly for NULL values than C#, so don’t forget to check your objects for NULL values. In Powershell this is very clean and easy to do.

But it is also easy to get wrong:

To see if a variable is null, simply check:

If (!$Variable) {some action}

Conversely, to verify if the variable has any value:

If ($Variable) {some action}

Just a few examples. Now quess the outcome for all of them.

$a=$null;  if ($a) {"'$a' has VALUE"} else {"'$a' is NULL"}
$a=$false; if ($a) {"'$a' has VALUE"} else {"'$a' is NULL"}
$a=0;      if ($a) {"'$a' has VALUE"} else {"'$a' is NULL"}
$a='';     if ($a) {"'$a' has VALUE"} else {"'$a' is NULL"}
$a="";     if ($a) {"'$a' has VALUE"} else {"'$a' is NULL"}
$a=1;      if ($a) {"'$a' has VALUE"} else {"'$a' is NULL"}

Now take an educated guess on the outcome. Read the rest of this entry »

Posted in .NET, CommandLine, Development, PowerShell, Software Development | Leave a Comment »

One of the niceses PowerShell 3.0 new features: Simpler Where Filter Syntax

Posted by jpluimers on 2014/03/04

You can check out which PowerShell you have by executing the $Host.Version or $PSVersionTable.PSVersion on a line. You can even switch versions by applying the PowerShell -version switch on the command-line and they will both change.

One of the great features of the new PowerShell 3.0 features (besides New and Improved PowerShell 3.0 Cmdlets) is a simplified Where Filter Syntax.

So: this is how I get the PowerShell version information the easy way from a command prompt:

PowerShell $PSVersionTable.PSVersion

–jeroen

via:

Posted in .NET, CommandLine, Development, PowerShell, Software Development | Leave a Comment »

RemObjects Hydrogene got released March 1st, 2014 (via: Get Started with iOS Development using RemObject C#)

Posted by jpluimers on 2014/03/02

The estimate was that the Hydrogene bete would become public beta on March 1st 2014.

Well, Marc Hoffman did an even better announcement yesterday:

When, you are asking, is RemObjects C# going to be out? It’s out as of right now!Visit http://www.remobjects.com/cs for details, trial download, and (of course) to purchase. Let us know what you think!

BTW: Most of my guessed URLs were right (:

–jeroen

via: Get Started with iOS Development using RemObject C# | RemObjects Software « The Wiert Corner – irregular stream of stuff.

Posted in .NET, Development, Software Development | Leave a Comment »

Get Started with iOS Development using RemObject C# | RemObjects Software

Posted by jpluimers on 2014/02/28

Wow, just wow for this teaser:

This page provides a few videos to help you get started with RemObjects C# for iOS development.

and this:

This page provides a few videos to help you get started with RemObjects C# for Android (and Java) development.

It is about Hydrogene, a.k.a. RemObjects C#, which – like Oxygene – also adds a few extensions to the C# language, just like Jolyon speculated december last year.

It wil be in beta tomorrow (:

Summary of tools used for iOS:

Summary of tools used for Android:

Summary of tools used for iOS and Android

I’m gussing here, as the URL is not yet live, but from March 1st (tomorrow!) you should be able to download a beta of Hydrogene/RemObjects C# from http://www.remobjects.com/elements/hydrogene (Just like Oxygene is available from http://www.remobjects.com/elements/oxygene/).

.  .

–jeroen

via:

Posted in .NET, C#, Development, Software Development, Visual Studio and tools | Tagged: , , , , | 1 Comment »

.NET 4.5 versus 4.0 and C# 5 versus C# 4, or the funny way how StackOverflow closes good answers

Posted by jpluimers on 2014/02/27

I’m more and more amazed (actually I’m not, this is how life on forum-like communities when moderatorss take over) about which StackOverflow questsions get closed, and which ones stay alive.

It seems the best way is to ask longer questions way beyond what most moderatorss can grasp.

Closed:

Still open:

A great point in the comments of the first question is that

you can technically can write .NET 4.0 / C# 4 applications on a .NET 4.5 / C#5 equiped machine and deploy them on machines that only have .NET 4.0 and C# support.

Don’t. I learned that in the .NET 3.0/3.5 and C# 3.0/2.0 era that combining is bad as the version matrix allows for subtle combinations that are hard to test.

.NET 3.0 with C# 2.0 applications written on a system that had .NET 3.5 and C# 3.0 installed would occasionally fail on systems that only had .NET 3.0 and C# 2.0 installed.

–jeroen

Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, Development, Software Development | Tagged: | Leave a Comment »

PowerShell – Special Characters And Tokens (via: Welcome to Neolisk’s Tech Blog)

Posted by jpluimers on 2014/02/27

This and next week, a few PowerShell posts appear on my blog.

Victor Zakharov, also known as Neolisk collected all the Special Characters and Tokens used in PowerShell on one page (they are scattered around the PowerShell documentation if documented at all).

The page is so immensely useful when learning PowerShell that I’m really glad I found it.

It is even better than Less Than Dot – Blog – A Cheat Sheet for All the *{_(%#$] PowerShell Punctuation.

–jeroen

via: PowerShell – Special Characters And Tokens – Welcome to Neolisk’s Tech Blog.

Posted in .NET, Development, PowerShell, Scripting, Software Development | Leave a Comment »

PowerShell aliases (via: Top Ten PowerShell Aliases for DOS Commands)

Posted by jpluimers on 2014/02/26

In most programming environments, I tend to avoid abbreviations, especially since command-completion and parameter-completion makes it easier to write readable code.

Same fore PowerShell: the PowerShell ISE has great completion features.

Other people tend to use abbreviations, especially since many PowerShell aliases make it easier for people coming from a cmd or bash background.

Two Get-Alias commands I use quite often for researching aliases:

  • Get-Alias -Definition <name>
  • Get-Alias | Sort-Object Definition

The former gives you the CmdLet for an alias.
The latter all defines alises sorted by the CmdLet definition.

Two aliases that I tend to avoid are these:

While you are at it, there are also parameter aliases. Read Weekend Scripter: Discovering PowerShell Cmdlet Parameter Aliases on TechNet Blogs to learn more about these.

–jeroen

via: Top Ten PowerShell Aliases for DOS Commands.

Posted in .NET, CommandLine, Development, PowerShell, Software Development | Leave a Comment »

Genymotion (formerly AndroVM) is an Android x86 virtual machine appliance (via: install in VMware Player/Workstation – YouTube)

Posted by jpluimers on 2014/02/14

Very interesting: Install AndroVM in VMware Player/Workstation – YouTube.

The successor is Genymotion “the faster Android emulator”, and seems to have an easier installation path: Run Android on Your Desktop With Genymotion Android Emulator.

One of the drawbacks of going native: the Delphi for Android compiler currently only generates ARM Android code, otherwise this would be a great way to test your apps.

But it works fine if you use Java, Oxygene for Java or MonoDroid: much faster than the emulator (which you cannot run in a VM at all).

There seems to be a way to install ARM translation, so I need to check that out: android – How to install google play service in the genymotion (ubuntu 13.04) .Currently it doesn’t have drag and drop suport – Stack Overflow.

–jeroen

via: Koushik Dutta – Google+ – Even if Microsoft is considering supporting Android apps on….

Posted in .NET, Android, Android Devices, Delphi, Delphi XE5, Development, Mobile Development, Mono for Android, Power User, Software Development | Tagged: , | 4 Comments »

ManagedSpy now maintained by ForNeVeR (via: managed – What happened to ManagedSpy?)

Posted by jpluimers on 2014/02/13

ForNeVeR now maintains ManagedSpy, see his answer on StackOverflow

BTW, I’ve cloned the original ManagedSpy source code and maintaining the code today (for example, ported it to .NET4).

See project on GitHub.

–jeroen

via: managed – What happened to ManagedSpy? – Stack Overflow.

Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

.NET/C#: DBNull explained

Posted by jpluimers on 2014/02/11

The DBNull type is a very special type in .NET. It represents null values in databases, which are slightly different than null values in .NET.

The biggest confusion that people have with it is that it won’t convert to anything. Which means that you see a lot of questions like “System.InvalidCastException: Conversion from type ‘DBNull’ to type” “is not valid”.

You’d think the full name would be System.Data.DBNull, it is actually named System.DBNull. The reason is that various other functionality of the System namespace depend on it, for instance the System.Convert class.

DBNull was already present in .NET 1.x, so it predates nullable types that were introduced in C# 2 / .NET 2.

A null value on the database side will result in a DBNull instance.

If you want to explicitly pass a null value to a database, you use a DBNull.Value, which is a singleton.

Why DBNull

There is a very interestin question/answer series on StackOverflow about this: via .net – What is the point of DBNull? – Stack Overflow.

There are a few good arguments both for and against DBNull.

But the baseline is that DBNull predates the introduction in the .NET framework of genuine nullable types. Both their behaviour is slightly different, so DBNull had to stay.

Which means you have to deal with it every now and then.

Invalid casts

A bit more background on the invalid casts.

It is thrown like this:

            throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull"));

from

Convert.DefaultToType();

which is called from the DBNull method

    object IConvertible.ToType(Type type, IFormatProvider provider);

All other IConvertible methods are implementated like

bool IConvertible.ToBoolean(IFormatProvider provider)
{
    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromDBNull"));
}

So these all throw the same exception:

    bool IConvertible.ToBoolean(IFormatProvider provider);
    byte IConvertible.ToByte(IFormatProvider provider);
    char IConvertible.ToChar(IFormatProvider provider);
    DateTime IConvertible.ToDateTime(IFormatProvider provider);
    decimal IConvertible.ToDecimal(IFormatProvider provider);
    double IConvertible.ToDouble(IFormatProvider provider);
    short IConvertible.ToInt16(IFormatProvider provider);
    int IConvertible.ToInt32(IFormatProvider provider);
    long IConvertible.ToInt64(IFormatProvider provider);
    sbyte IConvertible.ToSByte(IFormatProvider provider);
    float IConvertible.ToSingle(IFormatProvider provider);
    ushort IConvertible.ToUInt16(IFormatProvider provider);
    uint IConvertible.ToUInt32(IFormatProvider provider);
    ulong IConvertible.ToUInt64(IFormatProvider provider);

–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, Development, Software Development | Leave a Comment »