My Software Notes

Useful things I discover

Archive for July 2010

VB.NET Syntax for Object Initializers

leave a comment »

I don’t use VB.NET very much, so I keep forgetting the object initializer syntax.  So for my own benefit (and anyone else’s who has the same problem) here it is:

Dim acct = New Account() With { .Id = 10, .Name = "Joe Schmoe" }

Array initializer syntax is more like the C# syntax:

Dim intArray As Integer = { 1, 2, 3 }

And combining the two:

Dim acctArray() As Account = { _
                             New Account() With { .Id = 1, Name = "Mary Contrary" }, _
                             New Account() With { .Id = 2, Name="Fred Flintstone" } _

I won’t make any comments about how ugly VB.NET is because that would just start an argument and I’m a peace loving guy 🙂


MSDN: VB 9.0 Object and Array Initializers
Wriju’s Blog: VB.NET 9.0: Object and Array Initializers


Written by gsdwriter

July 31, 2010 at 3:36 pm

Posted in Languages

Assembly Version/Fully Qualified Name from the Command Line using PowerShell

with 2 comments

I was logged into a server core installation of Windows Server 2008 and I wanted to get some details on an assembly file.  But how to do it from the command line?

I found this article by good ole Scott Hanselman: Output an Assembly Version/Fully Qualified Name from the CommandLine which is great if I could have compiled the C# console program and copied it over, but I couldn’t due to various security issues.  So instead I wrote the same thing in PowerShell.

It’s not particularly difficult, but it may save someone out there some time.  Put this into a ps1 file:

    $asmFile = $(Throw "Assembly Filename is required")
$asm = [System.Reflection.Assembly]::LoadFrom($asmFile)
echo $asm.FullName

And the output is something like:

ps: .\AssemblyFullName.ps1 "Reminder.exe"
Reminder, Version=, Culture=neutral, PublicKeyToken=null

Tell me if you finds this helpful.

Written by gsdwriter

July 12, 2010 at 1:06 pm

Posted in Tools