Read through this article on www.asp.net for a list of problems and solutions that you might (will) encounter: http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes
onsdag 15 juni 2011
ASP.NET 4: Breaking changes
måndag 13 juni 2011
VB.NET: Finding registered event handlers
It seems that you can only check for registered event handlers on custom events, and only by the obscure:
...
Public Event MyEvent As Action(Of T)
...
If MyEventEvent Is Nothing Then
...
So, it has to be a custom event, and you have to append 'Event' to the name of your event.. And Intellisense will not help you as it does not even allow you to type the name of your event if you have not started the line with RaiseEvent...
I can live with the fact that I have to append 'Event' to the name of my event, but why does it have to be a custom event? Why does it not work with other events such as Button.Click?
I suspect that this is because of that the field MyEventEvent might be private or protected though. So maybe you could do it via reflection. But come on.
fredag 10 juni 2011
PowerShell: Useful info about strings
PS> $mystring = "Hello bob"
PS> $parts = $mystring.split(" ")
PS> [System.String]::Format("{0} {1}", $parts[0], $parts[1])
Hello bob
There are also a few string-specific operators that can be used: -split, -join, -f (scroll down to 'Special operators')
PS> write-host $("Hello {0}" -f "bob")
Hello bob
Notice the use of $(...) here, it is a sub-expression that is required in this case to make sure that the expression is executed first and sent to write-host as a single argument. See about_Operators (scroll down to 'Special operators') for more information.
Furthermore, there are special cases such as -like, -contains and -match in comparison operators that makes our lives even easier.
Concatenating strings is done in the usual way, with the plus-sign. Using variables inside a string can be done when using double-qoutes. Escaping on the other hand is by using the backtick, not backslash as most of us are used to:
PS> $myname = "bob"
PS> $mystring = "Hello " + "$myname `"The drooling monkey`""
Hello bob "The drooling monkey"
And last but not least
A few wise words about the cmdlet Select-String and a "general rule" of PowerShell:If you're parsing a string in Windows PowerShell, you're doing something wrongDon Jones Read the article from Don Jones here
PowerShell: Fetching the current user
[Security.Principal.WindowsIdentity]::GetCurrent().Name
You could also use $Env:UserName and $Env:UserDomain, but these are not always what you might think at a first glance. They contain the name of the user in the active environment, which is not always the same as the user running the script.
Example (assume that the user running this line is 'foo'):
runas /user:bar /env "powershell myscript.ps1"
This would run the script as 'bar' specified, but with $Env:UserName set to 'foo' because of the parameter /env
PowerShell links
My posts
Technet
Windows PowerShell
Basic, task-oriented info.
Windows PowerShell Owner´s manual
A good starting place
Windows PowerShell Tips
Misc tips and tricks
Windows PowerShell Core
Misc useful stuff
'About' help topics
Really useful as reference for syntax etc.
Get-Help about_<topic>
Listed below are a few useful ones
- about_Automatic_Variables
- about_Comment_Based_Help
- about_Comparison_Operators
- about_Environment_Variables
- about_Escape_Characters
- about_Execution_Policies
- about_Functions_Advanced_Parameters
- about_Operators
- about_Scripts
- about_Split
- about_Switch
- about_Variables
Windows PowerShell CmdLet Help Topics
The same goes for these, you can type: Get-Help <cmdlet>