Totally forgot about this: YAPP – yet another pretty printer.
–jeroen
via: delphi – Save source code with formatting syntax highlight – Stack Overflow.
Posted by jpluimers on 2011/12/05
Totally forgot about this: YAPP – yet another pretty printer.
–jeroen
via: delphi – Save source code with formatting syntax highlight – Stack Overflow.
Posted in .NET, C#, Development, Prism, Software Development | Leave a Comment »
Posted by jpluimers on 2011/11/30
Even if you have used something for over a decade, you can learn about it :)
I was refactoring bits of code where someone clearly didn’t understand the benefits of enumerations, similar to this very contrived example:
using System;
namespace Demo
{
// explicit equivalence of:
// public enum TrafficLight { Red, Yellow, Green };
public enum TrafficLight { Red = 0, Yellow = 1, Green = 2 };
public class Program
{
public static void Main()
{
// old code:
Console.WriteLine(IntIsRedTrafficLight((int)TrafficLight.Red));
Console.WriteLine(IntIsRedTrafficLight((int)TrafficLight.Yellow));
Console.WriteLine(IntIsRedTrafficLight((int)TrafficLight.Green));
}
public static bool IntIsRedTrafficLight(int trafficLight)
{
return (trafficLight == (int)TrafficLight.Red);
}
}
}
The code was using way too many casts, and my goal was something as simple as this: Read the rest of this entry »
Posted in .NET, C#, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2011/11/15
When I saw code like this in a production app, I was speachless:
if (matcher.Trim().Length > 0)
{
if (eesteWhere){sqlWhere += "WHERE ";eesteWhere = false;}
else{sqlWhere += "AND ";}
sqlWhere += "m.matcher like '" + matcher.Trim() + "%' ";
}
Not once, twice, but hundred of fragments like these. Not generated, but hand copy-pasted. And the client thought they were running stable, reliable apps :(
This is soo XSCD ‘Exploits of a Mom‘ (aka Bobby Tables):
The department that wrote the code has been closed a while ago, but some serious refactoring time needs to be invested here, as all applications delivered by that department are vulnerable to SQL Exploits.
–jeroen
Posted in .NET, C#, C# 2.0, Database Development, Development, Software Development, SQL, SQL Server | Leave a Comment »
Posted by jpluimers on 2011/11/08
Every once in a a while I do WinForms development. On the .NET platform it still is the best way to create simple business applications that just, well: work.
WinForms apps are not fancy, but the actual users don’t care much, as long as they can their daily work done. They love fanciness of their mobile devices, but for stuff they use 8 hours a day, they just want something that works quickly, well and easily. So WinForms for a baseline is good.
WinForms historically has had two ways of automatically: Anchors and Dock (.NET 2 introduced another way using FlowLayoutPanel and TableLayoutPanel, but often they make things more complicated than needed).
One of the pitfalls of Docking is when you set Dock to Fill. Sometimes the affected control will be too large.
Every time that happens, I am baffled, as .NET is the only platform with that behaviour; I use other platforms too, and they don’t have this docking peculiarity (of course the have others, that’s the fun of using multiple platforms <g>).
–jeroen
Via: c# – Panel.Dock Fill ignoring other Panel.Dock setting – Stack Overflow.
Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, VB.NET, WinForms | 2 Comments »
Posted by jpluimers on 2011/11/03
Sometimes you just want to ask a user for a simple string of input.
The InputBox function is an easy way to do do this. It has a tiny issue with the icon (it uses the one that belongs to the application installation, not the icon in the project properties).
InputBox has been part of Visual Basic since the 90s. And it is very easy to use from C# and other .NET languages:
Microst.VisualBasic.Interaction.InputBox("Did you know your question goes here?","Title","Default Text");Sometimes you have to look a bit further than your regular toolbox for simple solutions.
I should dig up my 2006 session on the My Object in Visual Basic: that is also very easy to use in C#.
–jeroen
via: Input Message Box in C#?.
Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, VB.NET, VBS | Leave a Comment »
Posted by jpluimers on 2011/10/18
Many processes use or host the .NET run-time.
For Microsoft implementations of the CLR, this is a quick trick of listing them:
tasklist /m "mscor*" tasklist /m "clr.dll"
The first statement lists all processes that use or host .NET 1.x through 3.x.
The last statement lists all processes that user or host .NET 4.0
On my system, this is the output:
C:\Users\jeroenp>tasklist /m “mscor*”
Image Name PID Modules
========================= ======== ============================================
explorer.exe 1696 mscoree.dll, mscoreei.dll
PrivacyIconClient.exe 7256 MSCOREE.DLL, mscoreei.dll, mscorwks.dll,
mscorlib.ni.dll, mscorjit.dll
PaintDotNet.exe 459736 MSCOREE.DLL, mscoreei.dll, mscorwks.dll,
mscorlib.ni.dll, mscorjit.dll
C:\Users\jeroenp>tasklist /m “clr.dll”
Image Name PID Modules
========================= ======== ============================================
explorer.exe 1696 clr.dll
[/sourecode]
–jeroen
via: process – How to check if a program is using .NET? – Stack Overflow.
Posted in .NET, C#, Development, Power User, Software Development | 1 Comment »
Posted by jpluimers on 2011/10/13
With the and iOS 5 release today and the MonoDevelop 2.8 release last week, there is also a new MonoTouch 5.0 released that binds the two and allows you to develop iOS 5 using Mono.
Almost like a mirracle: on the iOS 5 release day, MonoTouch 5 gets released. Lot’s of new stuff to play with, just read the announcement :)
Quote: “If you already have MonoTouch, simply launch MonoDevelop and you will be prompted to update – it’s that easy!”
Be sure to also read the new MonoTouch 5 documentation on new iOS 5 features and the comprehensive API diff between MonoTouch 4.2 and 5.0.
–jeroen
Posted in .NET, C#, Development, Mobile Development, MonoTouch, Software Development, xCode/Mac/iPad/iPhone/iOS/cocoa | Leave a Comment »
Posted by jpluimers on 2011/10/12
Last week, Xamarin released version 2.8 of the MonoDevelop development environment.
Biggest feature is xCode 4 support (which integrated the Interface Builder therefore broke MonoDevelop 2.6).
Since it is hard to run xCode 3 on Mac OS X Lion (Mac OS X Lion more than prefers xCode 4), and you need at least xCode 4.2 beta to develop for iOS 5, this welcome upgrade when you are staying current on Mac OS X.
You can use MonoDevelop to create .NET applications for:
Be sure to read the MonoDevelop 2.8 release notes, as even the list of Major Highlights is long:
–jeroen
Posted in .NET, C#, Development, Mono for Android, MonoTouch, Software Development, xCode/Mac/iPad/iPhone/iOS/cocoa | 1 Comment »
Posted by jpluimers on 2011/10/12
When running on Windows, changing the current user is called impersionation.
There are various ways to do this in Windows, including
On the iSeries, there is only one way, as everything goes through the same API: use QSYGETPH (Get Profile Handle) to verify a username/password combination and obtain a handle to the authentication token, then use QWTSETP (Set Profile Handle) to change the user currently signed on, as for instance mentioned by Colin Williams directing to the CHGCURUSR tool on FreeRpgTools.com and an article on Swapping AS/400 User Profiles by Shannon O’Donnel that comes with source code.
On the iSeries, when you are done, you should use QSYRLSPH (Release Profile Handle) when done impersonating, and you need to get the handle from the original user profile if you want to return to it.
The IBM documentation contains a small sample with QSYGETPH, QWTSETP and QSYSRLSPH that sets and restores the profile handle (edit 20120214: it got moved to http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fapis%2Fapiexushand.htm)
Note that on both Windows ans iSeries, impersonation within a process/thread will make it run in the new context, but the process still keeps the identity of the user that started the process.
If you want to change that, then on both you need to start a new process from the impersonated thread.
In Windows, you can combine the impersionation and the creation of a new process by using the CreateProcessWithLogonW function (as mentioned at the Old New Thing by Raymond Chan). I’ve yet to find an equivalent on the iSeries.
–jeroen
Posted in .NET, C#, Delphi, Development, iSeries, Software Development | Leave a Comment »
Posted by jpluimers on 2011/10/11
Small but useful, especially in countries that have something else than a dot (.) as decimal digit separator (all of the green countries: probably more than you’d thought).![]()
The C# sourcecode is really simple use a NumberFormatInfo instance (or an instance of another class implementing IFormatProvider) in a Single.ToString call:
float number = 3.1415;
NumberFormatInfo numberFormatInfo = new NumberFormatInfo();
numberFormatInfo.NumberDecimalSeparator = ".";
numberFormatInfo.NumberGroupSeparator = string.Empty;
string numberString = number.ToString(numberFormatInfo);
The classes implementing IFormatProvider are CultureInfo, DateTimeFormatInfo and NumberFormatInfo.
–jeroen
Posted in .NET, C#, Development, Software Development | Leave a Comment »